HTTP POST Request key

Hi all,

The question is not really related to the Ionic Framework, however…

I have one might be very simple question. I have to do a POST Request to check voucher validity. The post request uses URL Params only (without value with key only) and I am confused how to manage it from the app?
If someone of you have any idea or solution it will be highly appreciated!!!
Here is what I am trying to achieve:

This is the API endpoint which I have to call ( passing application_module and voucher values)

https://xyz/api/check_voucher/application_module/voucher

What I have tried so far:

 let urlSearchParams = new URLSearchParams ();
 urlSearchParams.append('', 'myapplicationmodule/');
 urlSearchParams.append('', "myvouchercode");

return this.httpClient.post(environment.url, urlSearchParams );

Second attempt:

 let application_module = 'xyz/';
 let voucher = 'xyz'
 return this.httpClient.post(environment.url, application_module + voucher );

None of above mentioned methods have success. :confused:

I am so confused how to achieve this POST call without key… Is there any way to do that?

Thanks in advance guys!!

You’ve nailed two of the ways to pass things in URLs, so all that leaves is door #3: in the path itself.

Your first attempt is what you do when the backend wants something application/x-www-form-urlencoded. Your second try put it in the body of the request - what you want when the backend wants JSON. Option #3:

let url = `https://xyz/api/check_voucher/${application_module}/${voucher}`;
return this.httpClient.post(url);

If you have access to whoever designed this backend API, however, I would take a moment to ask them why they did it this way, though. Accepting as JSON in the body (your #2) would be far and away my first choice here, because the other two options put the specific information in the URL itself, which means it tends to get recorded in server logs (typically not desired in for something like this).

1 Like

thanks a lot :love_letter: