Do REST API URLs have to look like this?

后端 未结 7 748
孤独总比滥情好
孤独总比滥情好 2020-12-28 18:36

Is it true that to implement a RESTful API, one has to implement a URL structure that looks like this

http://example.com/post/
http://example.com/post/123
         


        
7条回答
  •  佛祖请我去吃肉
    2020-12-28 19:07

    A key aspect of REST is that the url is the resource. a uri like

    http://example.com/script.php?etc-etc-etc
    

    doesn't put the resource identifier in the resource portion of the uri. that's not to say that a RESTful API shouldn't ever use get parameters; in fact, that's just fine:

    http://example.com/posts?sort=date_asc&offset=20&limit=10
    

    might be a great way to get the URI's of the 3rd page of oldest posts. However, using get parameters in this way should only be used in requests where the method is also GET. PUT and especially POST methods should really use simple uri's with the resource that will be affected in only the path portion.

提交回复
热议问题