2

I want to make a get request with params and observe the whole response object instead of the body. But the get method only accepts two arguments. How can I achieve this?

const params = new HttpParams().set('q', 'cironunes');

this.http.get(server_utl, { params }, {observe:response});
2
  • Do you use Http or HttpClient ? Commented Jan 26, 2018 at 7:37
  • HttpClient from '@angular/common/http'; Commented Jan 26, 2018 at 7:37

2 Answers 2

4

The second parameter accept options which can have params and observe. So you can pass your data like this

this.http.get(server_utl, { params, observe: 'response' });

This is the signature of the method get

get(url: string, options: {...}): Observable<any>

and what can accept the options paraneter

headers?: HttpHeaders | {
    [header: string]: string | string[];
};
observe?: HttpObserve;
params?: HttpParams | {
    [param: string]: string | string[];
};
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean
Sign up to request clarification or add additional context in comments.

Comments

1
const params = new HttpParams();
params.set('key', 'value');
this.http.get(server_utl, {params, observe: 'response'});

You don't make GET requests with a body. The parameters are appended to the URL.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.