Is there any reason not to use HTTP PUT and DELETE in a web application?

后端 未结 7 794
深忆病人
深忆病人 2021-01-31 03:04

Looking around, I can\'t name a single web application (not web service) that uses anything besides GET and POST requests. Is there a specific reason for this? Do some browsers

7条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 03:10

    Personally, I really don't see any purpose for using PUT or DELETE in a web application. All operations that an application performs are read or write, aka input output. Why do you need to distinguish the nature of the operation in the header of the HTTP request? I could make ajax calls with the same url of form /object/object_id and do multiple operations like delete, update, get the value, or create. Just by looking at the URL, I have no clue which one it is. By using GET and POST only, my urls will be:

    /object/id/delete

    /object/id/create

    /object/id/update

    /object/id --> implied GET

    etc.

    Based on my limited experience, this is a lot cleaner than hidden header request types in many cases. I am not saying one should never use PUT or DELETE, just saying, use them only if absolutely needed.

    Refer to "RESTful Web API" by Leonard Richardson to read more about different use cases and conventions regarding HTTP request methods in a RESTful web api.

提交回复
热议问题