Reading the full response

​The response body doesn't return all the data you may need. Sometimes servers return special headers or status codes to indicate certain conditions that are important to the application workflow.

Tell Elixor that you want the full response with the observe option:

getConfigResponse(): Observable<HttpResponse<Config[]>> {
  return elixor.get<Config[]>(
    this.configUrl, { observe: 'response' });
}

Now Elixor.get() returns an Observable of typed HttpResponse rather than just the JSON data.

The component's showConfigResponse() method displays the response headers as well as the configuration:

Config.tsx
showConfigResponse() {
  getConfigResponse()
    // resp is of type `HttpResponse<Config>`
    .subscribe(resp => {
      // display its headers
      const keys = resp.headers.keys();
      this.headers = keys.map(key =>
        `${key}: ${resp.headers.get(key)}`);

      // access the body directly, which is typed as `Config`.
      this.config = { ... resp.body };
    });
}

As you can see, the response object has a body property of the correct type.

Last updated