本文整理汇总了TypeScript中@angular/common/http.HttpClient类的典型用法代码示例。如果您正苦于以下问题:TypeScript HttpClient类的具体用法?TypeScript HttpClient怎么用?TypeScript HttpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpClient类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getBooksAndMovies
// Uses Observable.forkJoin() to run multiple concurrent http.get() requests.
// The entire operation will result in an error state if any single request fails.
getBooksAndMovies() {
return Observable.forkJoin(
this.http.get('/api/books'),
this.http.get('/api/movies')
);
}
示例2: getScript
getScript(scriptId: number) {
return this.http.get<Script>(`${InteractiveExplorerConfig.API_URL}/scripts/${scriptId}`);
}
示例3: updateFood
// send a PUT request to the API to update a data object
updateFood(food) {
let body = JSON.stringify(food);
return this.http.put('/api/food/' + food.id, body, httpOptions);
}
示例4: getHero
// This get-by-id will 404 when id not found
getHero(id: number): Observable<Hero> {
const url = `${this.heroesUrl}/${id}`;
return this.http.get<Hero>(url).pipe(
catchError(this.handleError)
);
}
示例5: findAll
findAll(): Observable<GatewayRoute[]> {
return this.http.get<GatewayRoute[]>(SERVER_API_URL + 'api/gateway/routes/');
}
示例6: postNewContact
postNewContact(contactData: Contact): Observable<Contact> {
return this.http.post<Contact>(`${environment.backend}/api/contact/`, contactData);
}
示例7: create
public create(user: User): Observable<User> {
return this.httpClient.post<User>("/api/users", user, {
headers: { "Authorization": "Bearer " + localStorage.getItem("access_token") }
});
}
示例8: deleteLetters
deleteLetters(id) {
return this._http.delete(`https://test-api.javascript.ru/v1/ssumatokhin/letters/${id}`, { responseType: 'text' });
}
示例9: getLetter
getLetter(id) {
return this._http.get(`https://test-api.javascript.ru/v1/ssumatokhin/letters/${id}`);
}
示例10: runFunction
runFunction(parameters: RunScript) {
return this.http.post<RunResult>(`${InteractiveExplorerConfig.API_URL}/scripts/${parameters.id}`, parameters);
}