maku_at
maku_at

Reputation: 1687

jhipster - Angular HttpClient calls with option {observe: 'response'}

JHipster generated Angular Services uses an option {observe: 'response'} for httpClient calls e.g.

this.httpClient.get<IEntity>(`${this.resourceUrl}/${id}`, { observe: 'response' })...

Is there any special reason to do this? Why do they want to receive the full response. (maybe some generic handling of headers or so...)

TIA

Upvotes: 0

Views: 570

Answers (1)

Lia
Lia

Reputation: 11982

By default the HttpClient returns the body of the response. You can pass-in an object with an observe key set to a value of ‘response’ to get the full response. This can be useful to inspect for certain headers, for e.g:

getData() {
  this.http.get<Post>(this.url, { observe: 'response' }).subscribe(res => {
    this.powered = res.headers.get('X-Powered-By');
    this.postTitle = res.body.title;
  });
}

Upvotes: 2

Related Questions