识别正确的 HTTP 方法
Identify the correct HTTP method
我已经使用 spring boot 创建了一个 REST 网络服务。它具有以下网址的用户资源
/users => get the users in system.(GET)
/adduser => Post a new user.(POST)
/addFriend/{friendID} => this method is to add the friendID into the current logged-in friend(the user resource has friend list) now my doubt its Its a POST request of a GET request. Currently GET method has solved my problem. But I am not sure about the correct method which is right one logically.
这是一个 POST 请求。
根据Wikipedia:
The GET method requests a representation of the specified resource. Requests using GET should only retrieve data and should have no other effect.
和
The POST method requests that the server accept the entity enclosed in the request as a new subordinate of the web resource identified by the URI. The data POSTed might be, for example, an annotation for existing resources; a message for a bulletin board, newsgroup, mailing list, or comment thread; a block of data that is the result of submitting a web form to a data-handling process; or an item to add to a database.
否,Restful API 以资源为目标且不包含 URI 中的操作。
示例:
GET /users
=> 获取用户列表
GET /users/:userid
=> 通过 userid 获取用户信息
POST /users
=> 创建新用户
DELETE /users/:userid
=> 通过用户名删除用户
POST /users/:userid/friends
=>建立友谊,您可以发送正文包括另一个用户的 ID。(JSON/XML)
GET /users/:userid/friends/:friendid
=> 检查两个用户之间的朋友可能 return friendshipID 或 true/false
我已经使用 spring boot 创建了一个 REST 网络服务。它具有以下网址的用户资源
/users => get the users in system.(GET)
/adduser => Post a new user.(POST)
/addFriend/{friendID} => this method is to add the friendID into the current logged-in friend(the user resource has friend list) now my doubt its Its a POST request of a GET request. Currently GET method has solved my problem. But I am not sure about the correct method which is right one logically.
这是一个 POST 请求。
根据Wikipedia:
The GET method requests a representation of the specified resource. Requests using GET should only retrieve data and should have no other effect.
和
The POST method requests that the server accept the entity enclosed in the request as a new subordinate of the web resource identified by the URI. The data POSTed might be, for example, an annotation for existing resources; a message for a bulletin board, newsgroup, mailing list, or comment thread; a block of data that is the result of submitting a web form to a data-handling process; or an item to add to a database.
否,Restful API 以资源为目标且不包含 URI 中的操作。 示例:
GET /users
=> 获取用户列表
GET /users/:userid
=> 通过 userid 获取用户信息
POST /users
=> 创建新用户
DELETE /users/:userid
=> 通过用户名删除用户
POST /users/:userid/friends
=>建立友谊,您可以发送正文包括另一个用户的 ID。(JSON/XML)
GET /users/:userid/friends/:friendid
=> 检查两个用户之间的朋友可能 return friendshipID 或 true/false