question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Q: How would I make a DELETE request?

See original GitHub issue

I tried something like this:

function deleteData(item, url) {
  fetch(url + '/' + item, {
    method: 'delete'
  }).then(response =>
    response.json().then(json => {
      return json;
    })
  );
}

and I get Uncaught TypeError: Cannot read property 'then' of undefined

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

23reactions
luchillo17commented, May 25, 2017

A bit late to this but you could improve on it like

function deleteData(item, url) {
  return fetch(url + '/' + item, {
    method: 'delete'
  })
  .then(response => response.json());
}

response.json() already returns a promise with json, so the last .then is unnecessary.

8reactions
knowbodycommented, Jul 8, 2015

@theopak yeah, what I was doing wrong - forgot to return the promise. So should look like:

function deleteData(item, url) {
  return fetch(url + '/' + item, {
    method: 'delete'
  }).then(response =>
    response.json().then(json => {
      return json;
    })
  );
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Simple DELETE request using fetch API by making custom ...
js file, first create an ES6 class DeleteHTTP and within that class, there is async fetch() function which DELETES the data from the...
Read more >
How do I send HTTP DELETE request? - ReqBin
In this HTTP DELETE request example, we send a DELETE request to the ReqBin echo URL to remove a resource from the server....
Read more >
How can I send a http delete request from browser?
As someone mentioned above, jQuery will do this for you, via the following syntax: $.ajax({ type: "DELETE", url: "delete_script.php", data: "name=someValue" ...
Read more >
How to create a DELETE request in Postman? - Tutorialspoint
Before creating a DELETE request, we shall first send a GET request to the server on the endpoint :http://dummy.restapiexample.com/api/v1/ ...
Read more >
How to send DELETE request using REST assured? - Tools QA
Delete method response is non-cacheable. The user cannot cache the server response for later use. Caching a delete request creates ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found