How to set response type as text while making HTTP call with Angular?

Sometimes, we want to set response type as text while making HTTP call with Angular.

In this article, we’ll look at how to set response type as text while making HTTP call with Angular.

How to set response type as text while making HTTP call with Angular?

To set response type as text while making HTTP call with Angular, we set the responseType property.

For instance, we write

this.http
  .post(
    "http://localhost:8080/order/addtocart",
    { dealerId: 13, createdBy: "-1", productId, quantity },
    { headers, responseType: "text" }
  )
  .pipe(catchError(this.errorHandlerService.handleError));

to call http.post to make a post request.

We set responseType to 'text' so we get a string as the response body value.

Conclusion

To set response type as text while making HTTP call with Angular, we set the responseType property.