问题描述
实现 RESTful API 是不是必须实现一个像这样的 URL 结构
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
/123
将用于编辑、删除
另一种提问方式是:像这样的 URL 可以称为 RESTful 吗?
Another way to ask the question is: can a URL that looks like this be called RESTful?
http://example.com/script.php?method=get_title&blogid=123
推荐答案
您不必像那样设计您的 URI 结构.它也可以是 /some_obscure_string/base64_encoded_title/unique_id
.这也可能是 RESTful,具体取决于其他几个因素.
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.
但是关于如何在 RESTful Web 应用程序中设计 URI 有几个最佳实践,其中之一就是尽可能简单和易读.
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.
您的示例 http://example.com/script.php?method=get_title&blogid=123
也可以是 RESTful,但查询参数表明某种 RPC- 或 RMI-改为使用 over-HTTP.
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.
总而言之:不要在您的 URI 设计中考虑太多.这将自动为您的应用程序提供良好且适当的 RESTful 设计.
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.
这篇关于REST API URL 必须像这样吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!