公开REST方式验证API
问题说明
我一般的REST的API设计的散热风扇,但我不能确定如何应用REST原则验证API。
I'm generally a fan of RESTful API design, but I'm unsure of how to apply REST principles for a validation API.
假设我们有查询和更新用户的个人资料信息(姓名,电子邮件,用户名,密码)的API。我们认为该功能的有益片暴露将是验证,例如查询一个给定的用户名是否是有效的和可用的。
Suppose we have an API for querying and updating a user's profile info (name, email, username, password). We've deemed that a useful piece of functionality to expose would be validation, e.g. query whether a given username is valid and available.
哪些在这种情况下,资源(多个)?什么HTTP状态codeS和/或标题应该使用?
What are the resource(s) in this case? What HTTP status codes and/or headers should be used?
作为开始,我有 GET /型材/验证
这需要查询字符串PARAMS并返回 204
或 400 。但
验证
显然是一个动词而不是名词。
As a start, I have GET /profile/validate
which takes query string params and returns 204
or 400
if valid or invalid. But validate
is clearly a verb and not a noun.
正确答案
类型的你所描述的事情肯定是更多的RPC风格在它的语义,但是,这并不意味着你不能在达到自己的目标一个RESTful的方式。
The type of thing you've described is certainly more RPC-style in its' semantics, but that doesn't mean you can't reach your goals in a RESTful manner.
有没有验证
HTTP动词,所以你有多少价值可以从构建围绕整个API得到什么?你的故事主要围绕为用户提供确定的能力给用户名是否可用 - 这听起来好像是一个简单的资源检索检查 - GET:/profile/username/... - 如果结果为404,名称是可用的。
There's no VALIDATE
HTTP verb, so how much value can you get from structuring an entire API around that? Your story centers around providing users with the ability to determine whether a given user name is available - that sounds to me like a simple resource retrieval check - GET: /profile/username/...
- if the result is a 404, the name is available.
这有什么突出的是,该客户端的验证就是这样 - 客户端。这是一个用户界面的关注,以确保数据被发送到服务器之前在客户机上进行验证。 RESTful服务不给丝毫客户端是否已经执行验证;基于它自己的验证逻辑,它会简单地接受或拒绝的请求。
What this highlights is that that client-side validation is just that - client side. It's a UI concern to ensure that data is validated on the client before being sent to the server. A RESTful service doesn't give a whit whether or not a client has performed validation; it will simply accept or reject a request based on its' own validation logic.
REST是不是一个包罗万象的范例,它不仅介绍了构建客户端服务器通信的方式。
REST isn't an all-encompassing paradigm, it only describes a way of structuring client-server communications.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcgfick
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22