Using POST as a workaround for the URL character limit

假如想象 提交于 2019-12-21 03:56:11

问题


If you have an API and support the POST operation only because of URL length limitations and the passing of complex parameters in the request, can you still say that you have a RESTful architecture?

What the above basically implies is that for this particular (read-only) API, there is no semantic difference between a GET and a POST, so what can be done with a GET can also be done with a POST (but not vice versa due to the limitations).

Would this still make the style of the architecture a RESTful one?


回答1:


Technically you are not violating any constraints. However you are severely reducing the self-descriptiveness of requests. This will result in the loss of the ability to cache responses. Being able to cache responses is an essential feature that is needed to build effective REST systems.




回答2:


So the question here is about restful architecture not for restful web services.If we go by the information given on Wiki-RestfulArch-Constraints , Yes it is.




回答3:


You will definitely lose functionality HTTP provides for GET requests. Proxies for instance make certain assumptions about GET requests (idempotence, cachability).

There's nothing wrong with POST perse, but maybe the REPORT method is more appropriate.




回答4:


The term Representational State Transfer was introduced and defined in 2000 by Roy Fielding in his doctoral dissertation. Section 6.3 explains how to apply REST to HTTP: http://www.ics.uci.edu/~fielding/pubs/dissertation/evaluation.htm#sec_6_3

Fielding does not claim that the use of POST is forbidden.

Wikipedia also mentions POST as a legal HTTP operation for RESTful web services: http://en.wikipedia.org/wiki/Representational_State_Transfer#RESTful_web_services




回答5:


Why don't you simply switch to including a body in the GET instead of using the query string?

Update

The RFC says the following:

A server SHOULD read and forward a message-body on any request; if the request method does not include defined semantics for an entity-body, then the message-body SHOULD be ignored when handling the request

Theres nothing in the specification that says that a body cannot be included in any of the methods. And all proxies, servers etc are obliged to include the body. It's up to the handler (you) to ignore the body or not.

As for the GET method, nothing states that it can not include a body.

This means that you can use a GET body as long as your web server supports it.



来源:https://stackoverflow.com/questions/5947414/using-post-as-a-workaround-for-the-url-character-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!