restful了解下


关于restful及oAuth2.0

http://www.ruanyifeng.com/blog/2014/05/restful_api.html
http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html

*客户端必须得到用户的授权(authorization grant),才能获得令牌(access token)。OAuth 2.0定义了四种授权方式

  • 授权码模式(authorization code)
  • 简化模式(implicit)
  • 密码模式(resource owner password credentials)
    客户端模式(client credentials)
麻麻我头好晕==运行流程
麻麻我头好晕==授权码模式
sf_remember
sid
segment的token

fiddler下的,比f12详细些,f12抓不到弹出的小窗内容

看一下github登陆segment的授权码模式
https://github.com/session
https://segmentfault.com/user/oauth/github
A:客户端申请认证的URI,包含以下参数:
    response_type:表示授权类型,必选项,此处的值固定为"code"
    client_id:表示客户端的ID,必选项
    redirect_uri:表示重定向URI,可选项
    scope:表示申请的权限范围,可选项
    state:表示客户端的当前状态,可以指定任意值,认证服务器会原封不动地返回这个值。(state项不用动态数据的话会存在CSRF漏洞)
C:  服务器回应客户端的URI,包含以下参数:
code:表示授权码,必选项。该码的有效期应该很短,通常设为10分钟,客户端只能使用该码一次,否则会被授权服务器拒绝。该码与客户端ID和重定向URI,是一一对应关系。
state:如果客户端的请求中包含这个参数,认证服务器的回应也必须一模一样包含这个参数。
redirectto
returnto
D:客户端向认证服务器申请令牌的HTTP请求,包含以下参数:
grant_type:表示使用的授权模式,必选项,此处的值固定为"authorization_code"。
code:表示上一步获得的授权码,必选项。
redirect_uri:表示重定向URI,必选项,且必须与A步骤中的该参数值保持一致。
client_id:表示客户端ID,必选项。
E:认证服务器发送的HTTP回复,包含以下参数:
access_token:表示访问令牌,必选项。
token_type:表示令牌类型,该值大小写不敏感,必选项,可以是bearer类型或mac类型。
expires_in:表示过期时间,单位为秒。如果省略该参数,必须其他方式设置过期时间。
refresh_token:表示更新令牌,用来获取下一次的访问令牌,可选项。
scope:表示权限范围,如果与客户端申请的范围一致,此项可省略。
segment收到保持io一致

貌似还是有点晕
看下别人的栗子
https://andaily.com/spring-oauth-server/resources/api/SOS_API-0.5.html


github

https://api.github.com/
https://api.github.com/user

{
  "current_user_url": "https://api.github.com/user",
  "current_user_authorizations_html_url": "https://github.com/settings/connections/applications{/client_id}",
  "authorizations_url": "https://api.github.com/authorizations",
  "code_search_url": "https://api.github.com/search/code?q={query}{&page,per_page,sort,order}",
  "commit_search_url": "https://api.github.com/search/commits?q={query}{&page,per_page,sort,order}",
  "emails_url": "https://api.github.com/user/emails",
  "emojis_url": "https://api.github.com/emojis",
  "events_url": "https://api.github.com/events",
  "feeds_url": "https://api.github.com/feeds",
  "followers_url": "https://api.github.com/user/followers",
  "following_url": "https://api.github.com/user/following{/target}",
  "gists_url": "https://api.github.com/gists{/gist_id}",
  "hub_url": "https://api.github.com/hub",
  "issue_search_url": "https://api.github.com/search/issues?q={query}{&page,per_page,sort,order}",
  "issues_url": "https://api.github.com/issues",
  "keys_url": "https://api.github.com/user/keys",
  "notifications_url": "https://api.github.com/notifications",
  "organization_repositories_url": "https://api.github.com/orgs/{org}/repos{?type,page,per_page,sort}",
  "organization_url": "https://api.github.com/orgs/{org}",
  "public_gists_url": "https://api.github.com/gists/public",
  "rate_limit_url": "https://api.github.com/rate_limit",
  "repository_url": "https://api.github.com/repos/{owner}/{repo}",
  "repository_search_url": "https://api.github.com/search/repositories?q={query}{&page,per_page,sort,order}",
  "current_user_repositories_url": "https://api.github.com/user/repos{?type,page,per_page,sort}",
  "starred_url": "https://api.github.com/user/starred{/owner}{/repo}",
  "starred_gists_url": "https://api.github.com/gists/starred",
  "team_url": "https://api.github.com/teams",
  "user_url": "https://api.github.com/users/{user}",
  "user_organizations_url": "https://api.github.com/user/orgs",
  "user_repositories_url": "https://api.github.com/users/{user}/repos{?type,page,per_page,sort}",
  "user_search_url": "https://api.github.com/search/users?q={query}{&page,per_page,sort,order}"
}


https://developer.paypal.com/docs/api/


刷下知乎长姿势

URL定位资源,用HTTP动词GET,POST,DELETE,DETC)描述操作
数据的元操作:
CRUD(create, read, update和delete,即数据的增删查改)

请求方式:
GET(SELECT):从服务器取出资源(一项或多项)
POST(CREATE):在服务器新建一个资源
PUT(UPDATE):在服务器更新资源(客户端提供完整资源数据)
PATCH(UPDATE):在服务器更新资源(客户端提供需要修改的资源数据)
DELETE(DELETE):从服务器删除资源

无状态即,所有资源可以通过url定位,不依赖其他资源或状态,直接进入该url就可以获取要的信息

*简而言之:
看Url就知道要什么
看http method就知道干什么
看http status code就知道结果如何
核心思想其实是把网页请求当成资源(名词而不是动宾短语)来看待,这三点都是为了实现如何把请求当成资源的

轮子哥的回答

soupui---https://www.ibm.com/developerworks/cn/opensource/os-cn-soapui/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,062评论 19 139
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,756评论 2 45
  • # Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列...
    aimaile阅读 26,736评论 6 427
  • 看了两罗的“长谈”,讲到如何学习,罗永浩提到,看书是一个方向,工作遇到到的一些困难,其实书上前人都已经总结好了。但...
    掏出来搞事阅读 1,801评论 0 0
  • 同事推荐的应用,作为文科出身的我,也应该在多年以后拿起笔来记录身边的人和物!希望大家多多支持!
    冰霜雪花阅读 1,306评论 0 0

友情链接更多精彩内容