Skip to content

Rest client is adding extra quotes to payload #229

Closed
@fushinoryuu

Description

@fushinoryuu

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

  1. Create the following IRequestOptions:
let options = {
    acceptHeader: "application/json",
    additionalHeaders: {
      "Content-Type": "application/x-www-form-urlencoded",
    }
  };
  1. 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
  1. Try to send the request:
let response = await client.create("someurl.com", body, options);
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions