Do REST API URLs have to look like this?

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

    You don't have to design your URI structure like that. It could also be /some_obscure_string/base64_encoded_title/unique_id. This could also be RESTful, depending on several other factors.

    But there are several best practices on how to design URIs in a RESTful web application and being as simple and as human readable as possible is one of them.

    Your example http://example.com/script.php?method=get_title&blogid=123 could also be RESTful, but the query parameters indicate that some kind of RPC- or RMI-over-HTTP is used instead.

    To sum it up: Don't put too much thought into your URI design. This will come automatically with a good and proper RESTful design of your application.

提交回复
热议问题