What is the best way to design a HTTP request when somewhat complex parameters are needed?

前端 未结 11 1032
一向
一向 2020-12-13 00:21

I have some web services that I am writing and I am trying to be as RESTful as possible. I am hosting these web services using a HTTPHandler running inside of IIS/ASP.NET/S

11条回答
  •  醉酒成梦
    2020-12-13 00:49

    If the query is too big to go in the URI, turn your query into a resource (like a saved search). I worked on a restful API for a hotel's booking system; the search query had too many params (preferences, rooming list...etc) so I turned it into a resource that I POST to the server. The server then replies with a URI uniquely identifing the search which body is the posted query + its results:

    POST http://hotels.xyz/searches
    body ...
    

    Response

    201 Created - Location: http://hotels.xyz/searches/someID
    Body ......
    

提交回复
热议问题