Passing Curly brackets in the service provider


#1

I have my service provider below, that makes a post request to the server,

this.http.post(`${Config.API_URL}/ride/book/{id}`, data, this.requestOptions).toPromise();

How do I pass this to the server with this curl bracket in this format {id}.
When i do they way it’s displays above, I get server error because it’s not getting the id as required


#2

Characters can be unsafe for a number of reasons. […] Other characters are unsafe because
gateways and other transport agents are known to sometimes modify such characters. These characters are “{”, “}”, “|”, “”, “^”, “~”, “[”, “]”, and “`”.

All unsafe characters must always be encoded within a URL. For example, the character “#” must be encoded within URLs even in systems that do not normally deal with fragment or anchor identifiers, so that if the URL is copied into another system that does use them, it will not be necessary to change the URL encoding.

The { symbol should be replaced with %7B and } with %7D.

this.http.post(encodeURI(${Config.API_URL}/ride/book/{id}), data, this.requestOptions).toPromise();


#3

Thanks for the clarification.
I did as instructed but the problem is persistent… Same error


#4

Wouldn’t you also want to use

${id}

Instead of

{id}

?
Or are you saying you literally want to include the brackets as part of the parameters you’re sending?
If so, maybe placing quotations around {id} would work. I’m not highly versed in string literal syntax, so that’s a shot in the dark


#5

I don’t want to pass the Curls { } but just the value in the curls which is supposed to be the item_id for instance, but the value after several attempts can’t still pass.


#6

Have you tried that? Assuming you stick with string literal syntax.
Or

`${Config.API_URL}/ride/book/` + `${id}`

As a last resort