Description
Environment
Node version: 13.12.0
Npm version: 6.14.4
OS and version: Windows 10
typed-rest-client version: 1.5.0
Issue Description
When trying to send a request with a payload other than JSON, the client is not able to recognize this and adds extra quotes since it performs a JSON.stringify()
on the payload.
This can be seen when trying to send a request with a body of application/x-www-form-urlencoded
type. This is the example payload I'm trying to send: client_id=some_client&grant_type=password&username=some_guy&password=the_password&client_secret=some_secret&scope=api
Expected behaviour
The rest client shouldn't call JSON.stringify()
on a payload that doesn't need it.
Actual behaviour
The rest client is adding extra quotes to the payload, making the request fail.
Steps to reproduce
- Create the following IRequestOptions:
let options = {
acceptHeader: "application/json",
additionalHeaders: {
"Content-Type": "application/x-www-form-urlencoded",
}
};
- Create a url encoded string that will be the payload for the request:
let body = client_id=some_client&grant_type=password&username=some_guy&password=the_password&client_secret=some_secret&scope=api
- Try to send the request:
let response = await client.create("someurl.com", body, options);
- If you step through the code, you will see that the client will add extra quotes on this line: https://github.com/microsoft/typed-rest-client/blob/master/lib/RestClient.ts#L110
I will be submitting a PR to try and get around this.