10

I am making a request to an API in which they sign their response body with a private key and send me the signature in a header. I am supposed to use their public key to validate the signature with the original response body but at the moment axios parses the response data there is something that is changing in it which makes the signature invalid. Is there some way to get the raw response data with axios?

I am doing a post request and want to get the string of the JSON object that axios automatically parses for me.

Juan Casian
  • 346
  • 3
  • 9

1 Answers1

14

You can set a "identity" transformResponse.

let res = axios.get("url",
{ transformResponse: (r) => r }); //null transform (we do not want to parse as JSON);

//res.data should now contain a plain unparsed string

Not sure if setting transformResponse to null does the same thing as the identity transform.

Grynn
  • 1,254
  • 11
  • 18
  • Hi Can we do this for post call as well? If possible then what is the syntax for post call – Dattatreya Kugve Apr 09 '23 at 17:43
  • Mostly the same: axios(method: "post", url: "url", transformResponse: r=>r, data: .., headers: ... ) see: https://axios-http.com/docs/req_config – Grynn Apr 10 '23 at 18:26