php - restful api和普通的接口有什么不同吗?
迷茫
迷茫 2017-05-16 13:11:54
0
2
874

看了一下网上对 restful api的解释,我感觉这个和我们平时写的接口没什么不同啊,都是通过HTTP的get或者post请求传输数据,返回json格式或者xml格式。

就算 restful api多了这些请求方式:
PUT:在服务器更新资源(客户端提供完整资源数据)

DELETE:从服务器删除资源

HEAD : 从服务器获取报头信息(不是资源)

但是他们最多只是一种传输数据的方式而已,比如说 DELETE是删除资源,我们要删除一篇文章,是不是要传一个文章ID到服务器,但是具体的逻辑代码还不是和普通的接口一样的写法,我直接用get传文章ID不就行了吗,为什么要用DELETE传输方式呢?

感觉我还是对restful api理解的还不够,现在还体会不到他与普通的接口有什么不一样

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
左手右手慢动作

RESTful API is just the design specification or a set of design theories for API.

Looking at the two points of URL and Method, you can understand it like this: URL is used to uniquely identify an Internet resource, and Method is used to identify what operation the current request is to perform on the resource.

Of course you can GET http://www.xx.com/user?id=123 to delete a user, but this does not comply with the RESTful API specification.

Conforming to the RESTful API specification should be DELETE http://www.xx.com/user/123.

Here http://www.xx.com/user/123 is used to identify an Internet resource (a user on a certain site), and DELETE is used to identify that my request is to delete a user.

For example, if I want to get the detailed information of this user, then my request is: GET http://www.xx.com/user/123. It’s still the same URL here, but if I request it using GET, the server should know I just want to get resource information, not delete.

世界只因有你

My personal understanding of Restful API is that it can more clearly tell others what this operation does. Of course you can use the get method to retrieve deleted data, but it is not as clear as delete.
Each framework has its own way of defining Restful api (for example, laravel and Yii2 name Restful api methods differently), but the two different definition methods have something in common, which is the corresponding addition, deletion and modification of method names. It's all set. In this case, when developers do development, they can clearly understand what this method is used for. At least the naming seems much clearer.
Personal humble opinion...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!