Where to set responseType to http GET for HttpClient in angular

Clash Royale CLAN TAG#URR8PPP
Where to set responseType to http GET for HttpClient in angular
I have a service that makes an http call to my backend:
exportSubs(param: Param): Observable<Sub>
return this.http.get<Sub>(
`$environment.apiBaseUrl/blah`,
headers: this.httpUtil.getReqHeaders)
.catch(error => this.httpUtil.handleError(error));
where do I set responseType?
@mast3rd3mon that's absolutely not what you normally do! Do you mean in the same object as the headers?
– jonrsharpe
Aug 6 at 15:16
Did you read the docs? They show exactly where to set it.
– jonrsharpe
Aug 6 at 15:18
@jonrsharpe yes it is what you do, its the
Accept header, unless he means what the angular http response type is, in which case it is already set to an array of Sub– mast3rd3mon
Aug 6 at 15:18
Accept
Sub
@mast3rd3mon I think you misunderstand the question, I'd suggest also reading the docs I just linked.
– jonrsharpe
Aug 6 at 15:19
1 Answer
1
You can specify that the data to be returned is not a JSON using the responseType. See the Requesting non JSON data
responseType
In your example, you should be able to use:
return this.http.get(
`$environment.apiBaseUrl/blah`, responseType: 'text' )
EDIT
You can set the responseType as blob,
return this.http.get(`$environment.apiBaseUrl/blah`, responseType: 'blob' );
That's not even valid syntactically, so I doubt you tried it.
– jonrsharpe
Aug 6 at 15:17
i have not tried it, its just the sample
– Sajeetharan
Aug 6 at 15:18
then I get error: "Expected 1-2 arguments, but got 3."
– Drew13
Aug 6 at 15:22
@Drew13 sounds like youre passing an extra parameter into the call,
get methods only take 2 paramaters, the url and optional http options– mast3rd3mon
Aug 6 at 15:25
get
@mast3rd3mon yeah I had to get rid of where I set my headers. I need my responseType to be of type 'blob'. I'll just figure it out
– Drew13
Aug 6 at 15:27
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
in the headers like normal
– mast3rd3mon
Aug 6 at 15:15