In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain the example analysis of Restful API for you in detail. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Restful:
Essence: a style of Software Architecture
Core: resource oriented
Problem to be solved: reduce the complexity of development and improve the scalability of the system
Design concepts and guidelines:
Everything on the network can be abstracted as a resource.
Each resource has a unique resource identity, and the operation of the resource does not change these identities.
All operations are stateless
HTTP protocol:
URL:port [server port, default is 80], path [path to access resources], query-string [data sent to http server], anchor [anchor]
Request: composition format [request line, message header, request body]
Request line: format [Method Request-URI HTTP-Version CRLF], for example [GET / HTTP/1.1 CRLF]
Request method: GET, POST, HEAD, PUT, DELETE, OPTIONS
Response: composition format [status line, message header, response body]
Status line: format [HTTP-Version Status-Code Reason-Phrase CRLF], for example [HTTP/1.1 200OK]
Commonly used status code: 200 OK,400 Bad Request,401 Unauthorized,404 Not Found,500 Internal Server Error,503 Server Unavailable
Restful API (six elements):
Resource path (URI): in Restfull architecture, each URL code has a resource, so there can be no verbs in the URL, only nouns. Generally speaking, nouns in API should be plural.
HTTP verb: operation on a resource (CURD), denoted by a HTTP verb (predicate).
GET [withdraw resources from the server (one or more)]
POST [create a new resource on the server]
PUT [updates the resource on the server (the client provides the full resource after the change)]
PATCH [update resources on the server (client provides changed properties)]
DELETE [remove resources from server]
Filtering information: if there are a large number of records, it is impossible for the server to return them all to the user. API should provide parameters to filter the returned results.
Status code: the status code and prompt information returned by the server to the user, using the standard HTTP status code.
200 OK server successfully returns the data requested by the user, which is idempotent
201 CREATED successfully created or modified data
204 NO CONTENT deleted data successfully
The request made by 400 BAD REQUEST users is incorrect and the operation is idempotent.
Unauthorized indicates that the user is not authenticated and cannot perform the current operation.
403 Forbidden indicates that user access is prohibited
Error handling: if the status code is 4XX or 5XX, the error message should be returned to the user. Generally speaking, error is used as the key name and error information as the key value in the returned information.
{"error": "Parameter error"}
Returned results: for different operations, the results returned by the server to the user should meet the following specifications
GET / collections [returns a list of resource objects (array)]
GET / collections/identity [returns a single resource object]
POST / collections [returns the newly generated resource object]
PUT / collections/identity [returns the complete resource object]
PATCH / collections/identity [returns modified properties]
DELETE / collections/identity [returns an empty document]
This is the end of this article on "sample Analysis of Restful API". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.