To construct Http Post URL with form params with the JavaScript Axios Http client, we use the querystring
module.
For instance, we write
const querystring = require("querystring");
//...
await axios.post(
authServerUrl,
querystring.stringify({
username: "abcd",
password: "1235!",
client_id: "user-client",
}),
{
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
}
);
to call post
with the authServerUrl
and a query string we get by calling querystring.stringiy
with an object with the query parameters.
And we set the request headers by setting headers
to an object with the headers.