Understand RESTful API

Disclaimer: This article is a blogger sigmarising original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/sigmarising/article/details/88777310

Understand RESTful API


REST (REpresentational State Transfer), namely "presentation layer state transfer", first appeared in Roy Thomas Fielding (involved in the design of the HTTP protocol, Apache server) PhD thesis (2000).

论文地址:Architectural Styles and
the Design of Network-based Software Architectures

API is a RESTful design style, which is compared to SOAP and XML-RPC is more simple to use, now has been a wide range of applications.


1. REST and RESTful API

REST describes an interactive form of client and server in the network, but REST itself is not practical and useful is how to design RESTful API (REST-style network interface).


2. RESTful API design

Design Rule 2.1 of the resource URI

URI used only nouns (usually plural) to specify resources, in principle, prohibit the use of verbs . API should be deployed to the exclusive domain under, consider joining the API version .

API should support for the {id}operation of a single resource.

https://api.test.com/v1/books 		# 一组资源
https://api.test.com/v1/books/137	# 单个资源 

# 错误的例子
https://api.test.com/v1/getBooks	# API 中出现了动词

The method of HTTP 2.2 request indicates CRUD operations

  • GET : access to resources
  • PUT : Updates Resources
  • POST : New Resource
  • DELETE : Delete Resource

It is noteworthy that, RESTful and there is no "official" standard , so that different Web applications, HTTP verb semantics represented may vary, but generally are similar.

2.3 forms and status code

Use some form of expression between Server and Client to deliver resources, usually json, it can be in other forms.

Via HTTP status code, it can directly reflect the results.

2.4 separate front and rear ends

Web terminal without using PHP, JSP, ASP architecture, changed the front end rendering, front-end routing (Angular, React, Vue). End and Web Server to transfer data and changing the data state is only the API using a RESTful .


3. Summary

  • From URI intuitively clear objects to be operated
  • The method can be understood intuitively from the HTTP operations do
  • You can intuitively understand the status code from the operating results

Reference links

Guess you like

Origin blog.csdn.net/sigmarising/article/details/88777310