Reputation: 1336
I have an question: how can I use POST HTTP method to simulate CRUD paradigm. I know that I can use POST to update and create but how can I delete and retrieve a resource using POST?
Upvotes: 1
Views: 319
Reputation: 31560
To use REST you should
It doesn't make sense to POST
to a url to GET
data from it, that will confuse your users.
For example, with jquery with the following you create a user
$.ajax({
url: 'http://example.com/users,
type: 'POST',
data: user
})
...and then you could update it
$.ajax({
url: 'http://example.com/users,
type: 'PUT',
data: user
})
...or maybe delete it
$.ajax({
url: 'http://example.com/users,
type: 'DELETE'
})
and try to GET it to see if it's still there
$.ajax({
url: 'http://example.com/users
})
(I omitted the callbacks for simplicity)
Upvotes: 1
Reputation: 2317
HTTP has DELETE and GET so you should not use POST for such actions.
https://www.rfc-editor.org/rfc/rfc2616
Upvotes: 1