Restful is the most popular interface design specification at the moment. It is a specification that both front-end and back-end must know. This specification defines that in interface development, in each process,
theprotocol
client should use when communicating with the back-end service through the API. The HTTPS protocol
domain name
API should be deployed under a dedicated domain name and should be kept as simple as possible. If you are sure that the API is very simple and will not be further expanded, you can consider placing it under the main domain name. Here are two common URL root examples:
version (Versioning)
under the main domain namemust remain backward compatible. You must introduce new versions of APIs while ensuring that old version APIs are still available. Therefore, a version support
address (path) should be provided for the specific URL of the routing (router)
API.
As for whether the URL must use hyphens (-) or underscores (_), there is no hard and fast rule, but it must be consistent with a style based on the team's situation
verb (request method method)
is a specific operation type for resources, represented by HTTP verbs. There are five commonly used HTTP verbs (the corresponding SQL commands are in brackets).
url parameters
All URL parameters must be in all lowercase and must use underscore type parameter form. The paging parameters must be fixed to page and page_size.
The response (Response)
must select an appropriate HTTP status code.
Data must be returned in JSON format.
All errors must be formatted uniformly.
The common status code
error format
'message' => ':message', // Detailed description of the error 'errors' => ':errors', // Detailed error description of the parameters, 422 and other statuses provide 'code' => ':code', // Business-defined exception code 'status_code' => ':status_code', // http status code 'debug' => ':debug', // debug Information, non-production environment provides
what is the message?
HTTP messages are used to exchange information when HTTP requests and responses. Messages that flow into the server from the client
are divided into two categories: request messages
and response messages. The basic message structures of request and response messages are the same, and they are composed of three parts:
axios
compatible browser and node server create XMLHttpRequests from the browser
Creating http requests from node.js
supports Promise API
Supports interception of requests and responses, conversion of request data and response data, cancellation of requests, automatic conversion of JSON, data client support for defense against XSRF
, come on, strangers! (I am no stranger to coming and going, I hope it will be helpful to you)
The above are these core knowledge points, which must be mastered in front-end and back-end communication! For more details, please pay attention to other related articles on the php Chinese website!