简单的问题,就最佳实践而言,像这样格式化我的 URL 更好:
http://www.example.com/search?query=hello&page=1
或像这样:
http://www.example.com/search/hello/page/1
请您提供您选择的正当理由。
简单的问题,就最佳实践而言,像这样格式化我的 URL 更好:
http://www.example.com/search?query=hello&page=1
或像这样:
http://www.example.com/search/hello/page/1
请您提供您选择的正当理由。
First one fits the situation where you want to "filter" your result if it gets a little too complicated, like this example:
cars.com/audi/sedan/a/4/black/manual.....
this is gonna take so long and complicated and result will be nightmare, but this would work better:
cars.com/mercedes/amg?color=white&transmission=manual
2nd way is just like thinking it of a 'folder'ed structure:
socialmedia.com/shares/1/comments/1/page/2
I am pretty sure you get the idea.
p.s. if you will provide your API to a brand new clients, who don't know anything about it, then first one is also more understandable but, i suggest you also have a API documentation which describes the parameters and the relevant poasible other calls as well. in this way your url formatting will be clearer and clients will not struggle to solve parameters in the url.
第一种方法不仅是功能性的,而且让人们了解名称/值对是什么。当然,您可以进行配置和字符串操作,使您的 URL 看起来像第二个示例并且仍然有效,但从可读性 pov 和功能易用性来看,第一个是最好的。