Go REST
M

Unable to use 'DELETE' method

Misterios Person almost 3 years ago 3996 views 3 replies

Good afternoon! Go rest got updated, and i had tried to manipulate data with root :"https://gorest.co.in/public/v2/users/2861547/posts. I can successfully get data from this user, can add some more posts to it, can patch them, but when it comes to deletion server gives 404 error. I wonder if method i use is wrong, but what i am doing is just getting post by its id, for example(https://gorest.co.in/public/v2/users/2861547/posts?id=44326) - here is link i fetch. Then i put method: 'DELETE' and all necessary headers but it still doesnt work. Maybe the problem is about fetching this link, i might need to fetch something instead but i dont really know what should i fetch instead. Thanks in advance.

here is my delete method(fetch link is mentioned above)

static delete(id) {
return fetch(${this.URL}?id=${id}, {
method: 'DELETE',
headers: this.HEADERS,
})
.then((res) => {
if (res.status !== 204 || !res.ok) {
throw new Error(Deletion was not successful)
}
})
}

3 replies
Z
zeevy almost 3 years ago

Can you please try.

DELETE /public/v2/posts/12345

Z
zeevy almost 3 years ago

Replace id with your post id

M
Misterios Person almost 3 years ago

Yes it worked, thanks a lot, appreciated!!!!

Your reply

Markdown supported