Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

new request javascript

const request = new Request('https://example.com', {method: 'POST', body: '{"foo": "bar"}'});

fetch(request)
  .then(response => {
    if (response.status === 200) {
      return response.json();
    } else {
      throw new Error('Something went wrong on api server!');
    }
  })
  .then(response => {
    console.debug(response);
    // ...
  }).catch(error => {
    console.error(error);
  });
 
PREVIOUS NEXT
Tagged: #request #javascript
ADD COMMENT
Topic
Name
8+3 =