If you want to pass variables to the API using GET that would be possible using query string. Remember to escape (urlencode) them properly! It is also possible to use POST, if you dont want your variables to be visible.
Manually formatting the query string is fine for simple situations. But it can become tedious when there are many parameters.
You could write a simple utility function that handles building the query formatting for you.
function formatParams( params ){
return "?" + Object
.keys(params)
.map(function(key){
return key+"="+encodeURIComponent(params[key])
})
.join("&")
}
And you would use it this way to build a request.
var endpoint = "https://api.example.com/endpoint"
var params = {
a: 1,
b: 2,
c: 3
}
return this.http.get(this.url+ formatParams(params)).toPromise();