[英]Determine appropriate URIs and resources in REST architecture
I'm relatively new to REST architecture, I have some question about how I should implement my RESTful API for my project.我对 REST 架构比较陌生,我对如何为我的项目实现 RESTful API 有一些疑问。
What URIs and resources would be appropriate for:哪些 URI 和资源适用于:
1. Login and logout? 1.登录和注销?
What I guess: POST or DELETE /api/users/auth
or POST or DELETE /api/users/login
?我猜是什么: POST or DELETE /api/users/auth
或POST or DELETE /api/users/login
?
2. Set, delete, or get user's avatar? 2. 设置、删除或获取用户头像?
What I guess: POST or DELETE or GET /api/users/{id}/avatar
.我猜的: POST or DELETE or GET /api/users/{id}/avatar
。 is it correct?这是正确的吗?
3. Verify by the sent code? 3.通过发送的代码验证?
What I guess: POST /api/users/{id}/verification
.我猜的: POST /api/users/{id}/verification
。 is it correct?这是正确的吗?
4. Change a single or some specific properties of the user? 4. 更改用户的单个或某些特定属性? (eg changing email or username) (例如更改电子邮件或用户名)
What I guess: PACTH /api/users/{id}
or PUT /api/users/{id}/email
.我猜的: PACTH /api/users/{id}
或PUT /api/users/{id}/email
。 is it correct?这是正确的吗?
Thanks in advance.提前致谢。
1. Login and logout? 1.登录和注销?
For web API you have to implement OAuth Authorization and then use对于 Web API,您必须实现OAuth 授权,然后使用
POST /oauth
to get token POST /oauth
获取令牌
2. Set, delete, or get user's avatar? 2. 设置、删除或获取用户头像?
There are no specific rules for that but humans SHOULD be able to easily read and construct URLs.对此没有特定的规则,但人类应该能够轻松阅读和构建 URL。 So, I think it will be ok所以,我想会没事的
POST or DELETE or GET /api/users/{id}/avatar
3. Verify by the sent code? 3.通过发送的代码验证?
It's up to you.由你决定。
4. Change a single or some specific properties of the user? 4. 更改用户的单个或某些特定属性? (eg changing email or username) (例如更改电子邮件或用户名)
Here I suggest to use PACTH /api/users/{id}
with json body to partly update or PUT /api/users/{id}
to full update user.这里我建议使用PACTH /api/users/{id}
和 json body 来部分更新或使用PUT /api/users/{id}
来完全更新用户。 Look at this package看看这个包
You can read Microsoft REST API Guidelines to more details.您可以阅读Microsoft REST API 指南以了解更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.