Get requests with JSON body option available in postman. but, How to send a body with get request in Axios?
Asked
Active
Viewed 412 times
0
-
You can certainly type a JSON body into the UI of Postman for a GET request, but does it actually send the body as part of the request? – Brendan Bond Dec 12 '21 at 07:01
-
I found [this answer](https://stackoverflow.com/questions/978061/http-get-with-request-body) from 2009, it might shed some light for you on why axios wouldn't include a body property in a GET request. – Brendan Bond Dec 12 '21 at 07:02
1 Answers
0
You can but you really shouldn't. Get requests are meant to be useful by just passing the url with query parameters when applicable. Either way, the method signature is for axios.get
is
get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
You can use it like this
const data: { ... }; // your payload, replace (...) for actual data
const config: AxiosRequestConfig = { data };
axios.get('/your-endpoint', config);

José Henrique
- 196
- 11