To make an HTTP request with a custom body as form url encoded in Typescript, you can use the built-in HttpClient module. First, you’ll need to import the HttpClient module:
index.ts64 chars2 lines
Assuming you want to make a GET request to an API with a custom body as form url encoded, you can do it like this:
index.ts313 chars10 linesHere, we have created a new instance of URLSearchParams and set the required key-value pairs to the body. Then, we have set the Content-Type header to application/x-www-form-urlencoded. Finally, we have passed the headers and the body to the HttpClient’s get method as options.
You can use post method instead of using get to send a post request with the same body data.
gistlibby LogSnag