Elixor
  • Elixor
  • Setup
  • Making a GET request
    • Why write a separate service file
    • Type-checking the response
    • Reading the full response
  • Sending data to the server
    • Adding headers
    • Making a POST request
    • Making a DELETE request
    • Making a PUT request
  • Error handling
    • Getting error details
    • retry()
  • Observables and operators
  • Requesting non-JSON data
  • Advanced Usage
    • Configuring the request
    • Debouncing requests
    • Intercepting requests and responses
    • Listening to progress events
  • Security: XSRF Protection
Powered by GitBook
On this page

Was this helpful?

  1. Making a GET request

Reading the full response

PreviousType-checking the responseNextSending data to the server

Last updated 6 years ago

Was this helpful?

​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 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.

Elixor.get()