php - Is there any difference between restful api and ordinary interface?
迷茫
迷茫 2017-05-16 13:11:54
0
2
939

After looking at the explanation of restful api on the Internet, I feel that this is no different from the interface we usually write. They all transmit data through HTTP get or post requests and return json format or xml format.

Even if the restful api has these request methods:
PUT: Update resources on the server (the client provides complete resource data)

DELETE: Delete resources from the server

HEAD: Get header information (not resources) from the server

But at most they are just a way to transmit data. For example, DELETE is to delete resources. If we want to delete an article, do we need to pass an article ID to the server, but the specific logic code is not an ordinary interface. In the same way of writing, can't I just use get to directly transfer the article ID? Why do I need to use the DELETE transmission method?

I feel like I still don’t understand RESTful API well enough, and I still can’t understand how it is different from ordinary interfaces

迷茫
迷茫

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

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