Reputation: 742
I have done some reading regarding GET and POST methods and know that GET method should be used when fetching data where the parameters are in URL. Whereas POST in general should be used to store data with data in the body.
But, I have an API that takes JSON as input. So I think I need to use POST method but what bothers me is that I won't make any changes to backend. I just need to fetch data according to the parameters in the JSON.
Would it be a bad practice to use POST method just to accept JSON even though no changes will be made? If so, what other approaches can I take? Thank you
Upvotes: 0
Views: 4221
Reputation: 139
This is how I use fetch to make a post with json data.
const data = {name : "toto", age : "12"}
fetch(url, {
method: "POST",
headers: { "content-type": "application/json" },
body
}).then(
console.log(data added !)
)
Upvotes: 0