RESTful service using only GET and POST methods

RESTful services are implemented currently with GET, POST, PUT , PATCH and DELETE or at least using 4 of that. (usually method PATCH is not used).

Is it possible to implement a RESTful API using only GET and POST making the post behave as a POST, PUT or DELETE, depending on some parameter passed in url or headers or just as that article mention doing a semantic url like: /users/delete /users/update

I was searching something like that and found that article but it is not very complete and is a little old. https://www.infoq.com/news/2010/06/get-post-alone-restful

I know that in some web frameworks (like Django) they only allow method POST and GET, but i think this occur for compatibility reasons, with previous versions of the framework.

In one hand Fielding talking about restful services the unique restriction is about semantics, but using the example above we have a sematic use ok. Without ambiguity between a POST or PUT or DELETE.


Yes, it is possible and it is even often done in practice for some specific use cases - for example because you can only use GET and POST in HTML forms, or when you need to have "PATCH" but it is not supported by the clients that you need to cooperate with.

If you use Express, there is method-override module:

  • https://github.com/expressjs/method-override
  • that lets you have an HTML form like:

    <form method="POST" action="/resource?_method=DELETE">
      <button type="submit">Delete resource</button>
    </form>
    

    that would delete a resource instead of posting it.

    The method override is usually done with a query parameter like "_method" above or with a special header like "X-HTTP-Method-Override" that can be set to "DELETE" or "PATCH" or whatever you want.

    链接地址: http://www.djcxy.com/p/71306.html

    上一篇: 我可以在哪里下载xamarin studio mac osx的asp.net mvc4模板

    下一篇: 仅使用GET和POST方法的RESTful服务