What is JSON?
What is Fetch API?
The Fetch API presents a new global fetch() method, which allows network requests to be made similarly to the XMLHttpRequest (XHR) method but more powerfully and flexibly. Fetch API is a better alternative to XMLHttpRequest and can be easily integrated with other technologies, such as Service Workers. The main difference between the Fetch API and XMLHttpRequest is that Fetch uses promises, which allows you to have a more straightforward and cleaner API without nested callbacks.
Below are example of getting JSON from the ReqBin echo URL using Fetch API.
How to POST JSON data using Fetch API?
To post JSON data to the server using the Fetch API, you need to tell fetch() to use the POST method and pass the JSON data in the "body" parameter. The Content-Type: 'application/json' HTTP header is necessary for the server to correctly receive and interpret the JSON data in the body of the HTTP message.
How to fetch JSON data using HTTP POST method?
To fetch JSON data from the server using the HTTP POST method, you need to tell fetch() to make a POST request by passing the "method: 'POST'".