0
I’m using the new library of angular to make requisitions, the HttpClient
. Along with the 4+ angle I am using here in the company for the backend, Java with Spring (boot).
The problem is occurring at the time of making a GET request to the backend, the HttpParams
, used with HttpClient
to pass parameters, does not do the replace of the variables and thus the backend denies the request.
Ex.: URL backend (Java): controller/obterByCodOne/{codOne}/codTwo/{codTwo}
Ex.: URL frontend (Angular): http://localhost:8080/controller/obterByCodOne/:codOne/codTwo/:codTwo
Code:
let params = new HttpParams()
.set('codOne', codOne)
.set('codTwo', codTwo);
Result (wrong): http://localhost:8080/controller/obterByCodOne/:codOne/codTwo/:codTwo?codOne=valueA&codTwo=valueB
The HttpParams
is not replacing the variable, but concatenating.
In other projects Angularjs was replaced the value normally using the $resource
. Instead of having q concatenate pieces of URL’s with variables until a final result is reached.
Anyway... I’m in this jam. Either I don’t understand the use of Httpparams or I don’t know how to use it.
Tried to leave the url only
controller/obterByCodOne
?– BrTkCa
@Lucascosta already yes. Thus returns 404 :\
– Jocsã
@LINQ which file more you need? I just put this because I thought that was enough.
– Jocsã
Every link I encounter shows you mounting the url in your hand. Ex: http://javasampleapproach.com/frontend/angular/use-angular-httpclient-post-put-delete-data-springboot-rest-apis-angular-4
– Jocsã