不要REST API的URL都这个样子? [英] Do REST API URLs have to look like this?

查看:317
本文介绍了不要REST API的URL都这个样子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是真的,来实现一个RESTful API,就必须实现一个URL结构,看起来像这样

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

其中 / 123 将用于编辑,删除

要问这个问题的另一种方法是:可以在类似如下的URL调用REST风格

  http://example.com/script.php?method=get_title&blogid=123


解决方案

您不要的有无的设计你的URI结构这样。它也可能是 / some_obscure_string / base64_en coded_title / UNIQUE_ID 。这也可能是基于REST的,这取决于其他几个因素。

但也有如何在一个RESTful Web应用程序设计URI和是一样简单和人类可读地就是其中之一几个最佳实践。

http://example.com/script.php?method=get_title&blogid=123

您的例子也可以RESTful的,但查询参数表明,某种中RPC或者RMI-过HTTP来代替。

要总结:不要把太多心思到您的URI的设计。这将您的应用程序的一个很好的和适当的REST风格的设计自动出现。

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

where the /123 would be used for edit, delete

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

解决方案

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.

这篇关于不要REST API的URL都这个样子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆