Search code examples
resturlhttp-puthttp-delete

Is it a good restful URL design to avoid using DELETE and PUT?


I read an example of restful service, it only uses two HTTP method: get post. for example, there is a task list at the server. To design the restful URL, we can use:

www.example.com/task    GET. return all the task list. 
www.example.com/task/id  GET. return the specific task.
www.example.com/task/create   GET. return a task form.
www.example.com/task/create   POST. post the data from task form page.
www.example.com/task/update/id  GET. update a task with id, return a task form page.
www.example.com/task/update/  POST. update the task from the task form page.
www.example.com/task/delete/id GET. delete the task with ID.

In this way, the URL is very clear, user can understand the meaning of the URL. Is this a good practice of restful URL definition?

Should we use PUT, DELETE operation? If so, how to design for the upward URL? Thanks.


Solution

  • www.example.com/tasks     GET return all the task list. 
    www.example.com/tasks     POST Create a new task
    www.example.com/tasks/id  GET return the specific task.
    www.example.com/tasks/id  PUT update the task
    www.example.com/tasks/id  DELETE delete the task with ID.
    

    IMHO that's all the methods you need to have to deal with Tasks.

    • Use nouns but no verbs
    • Use plural nouns
    • Use HTTP verbs (GET, POST, PUT, DELETE) to do CRUD