Do REST API URLs have to look like this?

后端 未结 7 757
孤独总比滥情好
孤独总比滥情好 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:03

    RESTful URI design is all about resources access and they should be structured in the RESTful manner, so you should not have any query strings.

    e.g. of GET

    authors/

    authors/1

    authors/1/books

    authors/1/books/10

    authors/1/books/10/summary

    etc.

    Anything and everything is called RESTfull these days, just look at some of the responses by it's inventor Dr Roy Fielding and you'll get some ideas. It is worth doing some reading on the subject.

    P.S you do not need post,get etc in your URIs, HTTP protocol is at present mostly used for consuming REST APIs and you can pass verb as a part of the call. Also there is a concept of content negotiation i.e you can request any available format from REST API (json,xml atc).

提交回复
热议问题