DEV Community

Ehsan Ghaffarii
Ehsan Ghaffarii

Posted on

Answer: how to fetch data from this api using 'POST' method in javascript

try this


async function postData(url = '', data = {}) {
  const response = await fetch(url, {
    method: 'POST', // *GET, POST, PUT, DELETE, etc.
    mode: 'cors', // no-cors, *cors, same-origin
    cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
    credentials: 'same-origin', // include, *same-origin, omit
    headers: {
      'Content-Type': 'application/json'
      },

My solution to this issue was chosen as the best solution from the programmers' point of view.

Top comments (0)