本文整理汇总了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();
});
}
}
开发者ID:ishyfishyy,项目名称:aurelia-contacts,代码行数:29,代码来源:store.ts
示例2: beforeEach
beforeEach(()=> {
http = new HttpClient();
http = http.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl(teamcity)
.withDefaults({
headers: {
'Accept': 'application/json'
}
});
});
});
开发者ID:sasha-uk,项目名称:xradiate,代码行数:13,代码来源:api.spec.ts
示例3: constructor
constructor(private http: HttpClient) {
http.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl('https://api.github.com/');
});
}
开发者ID:ltrain777,项目名称:skeleton-navigation,代码行数:7,代码来源:githubservice.ts
示例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;
}
});
});
}
开发者ID:sigmaframeworks,项目名称:sigma-ui-framework,代码行数:60,代码来源:ui-http-service.ts
示例5: constructor
constructor(private _http: HttpClient, private _eventAggregator: EventAggregator) {
_http.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl('http://localhost:8080/api/');
});
};
开发者ID:JDTLH9,项目名称:aurelia-kaizen,代码行数:7,代码来源:todo-store.ts
示例6: students
static get students() {
return {
getAll() {
return httpClient.fetch('students/getAll');
},
register(user) {
return httpClient.fetch('oauth/register',
{
method: 'post',
body: json(user)
});
}
}
}
开发者ID:Lesslimit,项目名称:MeeToo,代码行数:14,代码来源:dataService.ts
示例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());
}
}
开发者ID:ghiscoding,项目名称:Realtime-TODO-Aurelia-RethinkDB,代码行数:16,代码来源:customerData.ts
示例8: create
create(entity:Pessoa){
return this.httpClient.fetch('pessoas',{
method: 'post',
redirect: 'follow',
body: json(entity)
});
}
开发者ID:Diego-Rocha,项目名称:stack-sample,代码行数:7,代码来源:pessoa-service.ts
示例9: getPosts
getPosts(): Promise<IPost[]>{
return this._http.fetch('../../../../data/posts.json').then(response => {
return response.text();
}).then(data => {
return JSON.parse(data);
});
}
开发者ID:avizcaino,项目名称:avizcaino.github.io,代码行数:7,代码来源:blog-service.ts
示例10: archiveAllCompleted
archiveAllCompleted(): Promise<Todo[]> {
return this.http.fetch(`${baseUrl}/archive-all-completed`, {
method: 'post',
body: null
})
.then(response => response.json());
}
开发者ID:ghiscoding,项目名称:Realtime-TODO-Aurelia-RethinkDB,代码行数:7,代码来源:todoData.ts
注:本文中的aurelia-fetch-client.HttpClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论