Introduction Introduction 1-1 restful and resources
restful What is?
Essence: A software architecture style
Core: resource-oriented
solved problem:
1. Reduce development complexity
2. improve system scalability
Design concepts and guidelines:
1. All things in the network can be abstracted as a criterion
2. Each resource has a unique resource identifier, the operation of these resources will not change logo
(Example: When you delete a resource, identity is still valid, but the identity represented by symbol does not exist)
3. All the operations are stateless
(You this operation and the previous operation was irrelevant)
Resources What is a resource
The so-called "resource" is an entity on the network, or is a specific information on the network. (A song, a video, etc.)
HTTP protocol described in 2-1 restful
HTTP protocol -url
HTTP is a part of the application layer protocol, it is characterized by the rapid introduction.
Path: schema: // host [: port] / path [# anchor] [query-string?]
(Mainly protocol header hostname route request)
specified by the schema underlying protocol used (for example: http, https, ftp)
ip address or domain name of the host server
port server port, default is 80 (https the default is 443)
Path path to access a resource
query-string data sent to http server (for resource filter)
anchor anchor (such as writing a document api, will be written in the same link below, if you need to locate a specific section or function)
HTTP protocol - request
Composition format: the request line, header message, request body
Request line:
Format: method (Request method) Request-url (request address) http-version (http request protocol version 1.0 1.1) crlf
For example: get / http / 1.1
Request method:
1. get resource request acquisition request-url identified
2. post additional new resources in the resource identified by the Request-url
3. head your head response message with a Request-url request acquiring resource identified
4. put a resource request to the server memory, and with its identity as a Request-url
5. delete resource delete request to the server identified by the Request-url
6. options request query performance server, or other relevant resource needs and options
HTTP protocol - response
Composition format: The status line, the message header, the state of the body
Status line: http-version status-code reason-phrase crlf
Examples: http / 1.1 200 OK
Common status codes:
200 OK successful client requests
400 Bad Request client requests a syntax error, it can not be understood by the server
401 unauthorized server receives the request, but refused to provide services
404 the requested resource does not exist
500 server unexpected error occurred
Current server 503 can not handle the client's request
2-2 architectural differences
Restful difference between architecture and other architectures with contrast webservice
效率与易用性:soap 各种需求不断补充其本身协议的内容,导致处理性能方面有些下降,难度上升,restful资源借口设计以及操作抽象
简化了开发者的不良设计,最大限度的利用了http最初的应用协议设计理念
安全性:对安全性要求比较高的项目,使用WebServiceAPI,对安全性要求比较低的使用RESTfulAPI
3-1 Restful设计要素
如何设计restful api
1. 资源路径 2.http动词 3.过滤信息 4.状态码 5.错误处理 6.返回结果
http动词:get,post,put×(更新,客户端提供改变后的完整资源),patch(更新,客户端提供改变的属性),delete
使用Restful api 返回的状态码就要和标准的http相同: 200 成功 201 新建或修改数据成功 204 删除数据成功 400 用户发送的请求有错误
401 表示用户没有认证,无法进行当前操作 403 用户访问是被禁止的 422 当创建一个对象时,发生一个验证错误 500 服务器发生错误 用户将无法判断发送的请求是否成功
3-2 DHC client
谷歌安装的插间
百度搜索:DHC client https://chromecj.com/web-development/2015-08/549/download.html
把下载下的文件后缀名改成zip,后面开发者工具加载这个文件夹就可以了
谷歌的网上应用商店搜索 DHC Client
postman代替
3-3 本地开发环境的搭建
开发环境的搭建:下载upupw.net 集成环境
www.upupw.net 下载