本文整理汇总了TypeScript中aurelia-fetch-client.HttpClient类的典型用法代码示例。如果您正苦于以下问题:TypeScript HttpClient类的具体用法?TypeScript HttpClient怎么用?TypeScript HttpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpClient类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(private http: HttpClient, private observerLocator: ObserverLocator) {
//localStorage.clear();
this.contacts = JSON.parse(localStorage.getItem(Constants.STORAGE_CONTACTS));
if (!this.contacts) {
http.configure(config => {
config.useStandardConfiguration().withBaseUrl('https://api.github.com/');
});
http.fetch('users')
.then(response => response.json())
.then(users => {
this.contacts = users.map((user: { id: number, login: string, avatar_url: string, type: string }) => {
let contact = new Contact();
contact.id = user.id;
contact.username = user.login;
contact.email = user.login + "@email.com";
contact.avatarUrl = user.avatar_url;
contact.description = user.type;
contact.checked = false;
return contact;
});
this.contacts = this.contacts.splice(20);
this.updateStorage();
this.applyObservers();
});
}
}
示例2: beforeEach
beforeEach(()=> {
http = new HttpClient();
http = http.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl(teamcity)
.withDefaults({
headers: {
'Accept': 'application/json'
}
});
});
});
示例3: constructor
constructor(private http: HttpClient) {
http.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl('https://api.github.com/');
});
}
示例4: constructor
constructor(public httpClient: HttpClient,
public appState: UIApplication,
public eventAggregator: EventAggregator) {
this.appState.info(this.constructor.name, 'Initialized');
let self = this;
httpClient.configure(
config => {
config
.withBaseUrl(UIConstants.Http.BaseUrl)
//.withDefaults({})
.withInterceptor({
request(request) {
appState.info(self.constructor.name, `Requesting ${request.method} ${request.url}`);
appState.IsHttpInUse = true;
//request.url = encodeURI(request.url);
return request;
},
response(response) {
appState.info(self.constructor.name, `Response ${response.status} ${response.url}`);
appState.IsHttpInUse = false;
if (response instanceof TypeError) {
throw Error(response['message']);
}
if (response.status == 401) {
eventAggregator.publish('Unauthorized', null);
}
else if (response.status != 200) {
return response.text()
.then(resp => {
let json: any = {};
let error = 'Network Error!!';
try {
console.log(resp);
json = JSON.parse(resp);
if (json.message) error = json.message;
else if (json.error) error = json.error;
else if (response.statusText) error = response.statusText;
} catch (e) { }
if (error) throw new Error(error);
return null;
});
}
return response;
},
requestError(error) {
appState.IsHttpInUse = false;
if (error !== null) throw Error(error.message);
return error;
},
responseError(error) {
appState.IsHttpInUse = false;
if (error !== null) throw Error(error.message);
return error;
}
});
});
}
示例5: constructor
constructor(private _http: HttpClient, private _eventAggregator: EventAggregator) {
_http.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl('http://localhost:8080/api/');
});
};
示例6: students
static get students() {
return {
getAll() {
return httpClient.fetch('students/getAll');
},
register(user) {
return httpClient.fetch('oauth/register',
{
method: 'post',
body: json(user)
});
}
}
}
示例7: save
save(customer: Customer): Promise<Customer> {
if (customer.id) {
return this.http.fetch(`${baseUrl}/${customer.id}`, {
method: 'put',
body: json(customer)
})
.then(response => response.json());
}
else {
return this.http.fetch(`${baseUrl}`, {
method: 'post',
body: json(customer)
})
.then(response => response.json());
}
}
示例8: create
create(entity:Pessoa){
return this.httpClient.fetch('pessoas',{
method: 'post',
redirect: 'follow',
body: json(entity)
});
}
示例9: getPosts
getPosts(): Promise<IPost[]>{
return this._http.fetch('../../../../data/posts.json').then(response => {
return response.text();
}).then(data => {
return JSON.parse(data);
});
}
示例10: archiveAllCompleted
archiveAllCompleted(): Promise<Todo[]> {
return this.http.fetch(`${baseUrl}/archive-all-completed`, {
method: 'post',
body: null
})
.then(response => response.json());
}