Answer the question
In order to leave comments, you need to log in
HttpClient: how to bind parameters to url?
Hello. I'm familiar with Angular.
I need to make a request to the address http://test/api/v1/person/10
It is clear that 10 is the id of the object, and it changes.
So, how to substitute this id in the url? I understand that you can stupidly add it to the url, but, IMHO, this is somehow not right.
I expected to see something like:
getPerson(id: number) : Observable<Person> {
return this.http
.get<Person>("http://test/api/v1/person/{id}", {pathParams : {id : id.toString()}});
}
{id}
is the placeholder for the parameter, but pathParams
the parameters themselves are passed to. But I didn't find it in the documentation. Isn't there something like this out of the box? Answer the question
In order to leave comments, you need to log in
That very simple option is the answer:
getPerson(id: number): Observable<Person> {
return this.http.get<Person>(`http://test/api/v1/person/${id}`);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question