本文整理汇总了TypeScript中aurelia-http-client.HttpClient类的典型用法代码示例。如果您正苦于以下问题:TypeScript HttpClient类的具体用法?TypeScript HttpClient怎么用?TypeScript HttpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpClient类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: convert
public convert(): Promise<void> {
if (!this.rawSql)
return;
return this
.client
.createRequest("/api/sql/format")
.asPost()
.withHeader('Content-Type', 'text/plain')
.withContent(this.rawSql)
.send()
.then(r => {
var result = JSON.parse(r.response);
this.formattedSql = result.Sql;
this.timeTaken = result.Duration;
this.showFormattedSql = true;
})
.catch(r => {
console.log(r.response);
this.showNotification({ message: r.response, type: "error" });
this.showFormattedSql = false;
});
}
示例2: getFunnyPosts
getFunnyPosts() : Promise<IRedditPosts> {
return this.http.jsonp('http://reddit.com/r/funny.json', 'jsonp')
.then(response => {
this.funny = response.response.data.children;
return this.funny;
});
}
示例3: getGifPosts
getGifPosts() : Promise<IRedditPosts> {
return this.http.jsonp('http://reddit.com/r/gifs.json', 'jsonp')
.then(response => {
this.gifs = response.response.data.children;
return this.gifs;
});
}
示例4: activate
activate(params: any) {
return this.http.get(`/api/schedulers/${params.schedulerName}/jobs/history`).then(response => {
let model = response.content;
this.entries = model.historyEntries;
this.errorMessage = model.errorMessage;
});
}
示例5: Promise
return new Promise((resolve) => {
let requestPromise = this.httpClient.createRequest(this.api.read)
.withParams(options.params || {})
.send();
requestPromise.then(response => {
let result = this.getReader().read(response.content);
resolve({
type: 'read',
success: true,
data: result.data,
total: result.total,
page: result.page,
limit: result.limit,
offset: result.offset
});
});
requestPromise.catch(() => {
resolve({
type: 'read',
success: false
});
});
});
示例6: createPost
createPost(text: string, options: any) {
this.ea.publish(new ApiStatus('Creating Post', { status: 'info' }));
var jsonText = {
text: text,
entities: {
parse_links: true,
parse_markdown_links: true
},
reply_to: 0
};
if (options.reply_to) { jsonText.reply_to = options.reply_to; }
this.isRequesting = true;
return this.http.configure((x: any) => {
x.withHeader('Authorization', 'Bearer ' + this.state.token);
x.withHeader('Content-Type', 'application/json');
}).post(`https://api.app.net/posts`, jsonText)
.then((response: any) => {
this.meta = response.content.meta;
this.isRequesting = false;
this.ea.publish(new ApiStatus('Post Created', { status: 'success' }));
return response.content.data;
}).catch((err: any) => {
this.isRequesting = false;
this.ea.publish(new ApiStatus('Unable to post', { status: 'error' }));
return {};
});
}
示例7: getGoogleLoginUrl
public getGoogleLoginUrl(redirectUrl: string) : Promise<string> {
return this.httpClient
.createRequest(`Authentication/Login/Google/Url?redirectUrl=${encodeURIComponent(redirectUrl)}`)
.asGet()
.send()
.then(response => response.content.url)
.catch(response => Promise.reject(response.content.message));
}
示例8: activate
activate(params: any) {
var teamId = params.id;
return this.httpClient.get('./team/'+teamId)
.then(response => {
this.team = new TeamViewModel(response.content);
});
}
示例9: nameChanged
nameChanged(newValue) {
if (newValue.length > 0) {
this.httpClient.get('/hello/' + newValue).then((response) => {
this.result = response.content.Result;
});
} else {
this.result = '';
}
}
示例10: getSummoners
public getSummoners(token: JsonWebTokenModel): Promise<Summoner[]> {
return this.httpClient
.createRequest("Summoners")
.asGet()
.withHeader("Authorization", `Bearer ${token.token}`)
.send()
.then(response => response.content)
.catch(response => Promise.reject(response.content.message));
}