1

I am trying to use an API which is of GET type and it is expecting the data in body, not as query parameter. I am using Axios as HTTP client but it seems Axios is not supporting body in GET request. Since the API is third party, I can not change it to read data from params or change the method to POST.

Is there any way to pass data in body using Axios or any other HTTP Client?

The same API is working with body when using with PHP Curl

Sabith
  • 1,628
  • 2
  • 20
  • 38

1 Answers1

0

Use data or params parameter of the GET according to your needs

Refer the docs for all the parameters

axios.get(< your request url >, {
  params: {
    custom_data : < Your Body here >
  }
}).then(...)

Also Refer

krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88
  • Axios with data will not work for GET request – Sabith Jan 17 '23 at 05:45
  • API is expecting data in body, not in params – Sabith Jan 17 '23 at 05:49
  • Just to correct you , Axios with data will work . Refer the docs https://www.npmjs.com/package/axios#axios-api. Based on your requirement pass it in `data` or `params` – krishnaacharyaa Jan 17 '23 at 05:51
  • Please check GET, not POST – Sabith Jan 17 '23 at 05:53
  • Please refer in the **Request Config** section in the [docs](https://www.npmjs.com/package/axios#axios-api) if you want data to work , you have to use optional config. It will work even with the GET , use `method='get'` as shown in the example – krishnaacharyaa Jan 17 '23 at 06:00
  • 1
    It is clearly mentioned 'data' will work only with methods 'PUT', 'POST', 'DELETE , and 'PATCH' in the docs. Which optional config you meant? – Sabith Jan 17 '23 at 06:20
  • Apologies, could you provide more information about the API you are using , what is it actually expecting in the GET request – krishnaacharyaa Jan 17 '23 at 06:40