My Url Params are too big. So I'm trying to get that content with passing it in request.body. The API works fine with postman while testing. But not able to fetch it in React
I'm using ExpressJS
API: http://localhost:5000/api/v1
React Code:
let result = await fetch("http://localhost:8080/autocomplete",{
method: 'GET',
body: {
"text": "something new"
}
});
console.log(await result.json()) // Not get my data here
ERROR:
TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have a body.
How i solve this issue ?
It is expected.
From mozilla docs, it mentioned: The HTTP GET method requests a representation of the specified resource. Requests using GET should only be used to request data (they shouldn't include data).
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET