当前位置:网站首页>Tslint annotations ignore errors and restful understanding

Tslint annotations ignore errors and restful understanding

2022-04-23 05:21:00 process1212

restful It is recommended to see the great God's blog

tslint Comment mark

ts Use the following comment in the file to temporarily ignore the error of the rule , Reference here

  • / tslint:disable /—— Ignore the error prompt in all the following code on this line
  • / tslint:enable /—— At present ts File re enable tslint
  • // tslint:disable-line—— Ignore the error prompt in the current line of code
  • // tslint:disable-next-line—— Ignore the error prompt in the next line of code

RESTful

A style of software architecture 、 Design style , and No standard , It just provides a set of design principles and constraints . It is mainly used for the software of interaction between client and server . Software designed based on this style can be more concise , More layers , It is easier to implement caching and other mechanisms .

Principle conditions :

Web The most important part of an application is REST The principle is , The interaction between client and server is stateless between requests . Every request from the client to the server must contain the information necessary to understand the request . If the server restarts at any point in time between requests , The client will not be notified . Besides , Stateless requests can be answered by any available server , This is very suitable for Cloud computing Or something like that . Clients can cache data to improve performance .

On the server side , Application state and function can be divided into various resources . Resources are an interesting conceptual entity , It's open to clients . Examples of resources are : Application object 、 Database records 、 Algorithm, etc. . Every resource uses URI (Universal Resource Identifier) Get a unique address . All resources share a unified interface , To transfer state between client and server . It's standard HTTP Method , such as GET、PUT、POST and DELETE.Hypermedia Is the status of the application engine , Resources are represented by Hyperlinks interconnection .

PRC: Remote procedure call
RFC:request for comments Request comments

The purpose of my article , I want to be consistent with the principle of architecture , Understand and evaluate the architecture design of web-based applications , Get a powerful 、 Good performance 、 Architecture suitable for communication .REST A set of architectural constraints and principles .

REST It doesn't create new technology in itself 、 Components or services , And hidden in RESTful The idea behind it is to use Web The existing characteristics and capabilities of , Better use of existing Web Some criteria and constraints in the standard . although REST Self acceptance Web Technology has a profound impact , But in theory REST The architectural style is not tied to HTTP On , Just for now HTTP Is the only one with REST Relevant examples . So what we're describing here REST through HTTP Realized REST.

From the definition of resources 、 obtain 、 describe 、 relation 、 State change and so on , List and explain some key concepts :

Resources and URI

** Anything , As long as there is a need to be quoted , It's a resource . Resources can be entities ( For example, cell phone numbers ), It can also be just an abstract concept ( For example, value ) **

URI:uniform resource identifier

URI The design of the system should follow the principle of addressability , Self descriptive , Need to give people an intuitive connection in form .

Unified resource interface

RESTFul Architecture should follow the principle of unified interface , The unified interface contains a limited set of predefined operations , No matter what kind of resources , All access resources through the same interface .

GET

  • Safe and idempotent
  • Get representation
  • Get representation on change ( cache )
  • 200(OK) - Indicates that... Has been issued in the response
  • 204( There is no content ) - If the resource is empty, it means
  • 301(Moved Permanently) - Resources URI Has been updated
  • 303(See Other) - other ( Such as , Load balancing )
  • 304(not modified)- The resource has not changed ( cache )
  • 400 (bad request)- A bad request ( Such as , Parameter error )
  • 404 (not found)- Resource does not exist
  • 406 (not acceptable)- The server does not support the required representation
  • 500 (internal server error)- General error response
  • 503 (Service Unavailable)- The server is currently unable to process the request

POST

  • Not safe and idempotent
  • Using server managed ( Automatically generate ) Instance number of create resource
  • Create sub resources
  • Partial update resources
  • If it's not modified , But update the resources ( Optimism lock )
  • 200(OK)- If an existing resource has been changed
  • 201(created)- If a new resource is created
  • 202(accepted)- Processing request accepted but not completed ( Asynchronous processing )
  • 301(Moved Permanently)- Resources URI Be updated
  • 303(See Other)- other ( Such as , Load balancing )
  • 400(bad request)- A bad request
  • 404 (not found)- Resource does not exist
  • 406 (not acceptable)- The server does not support the required representation
  • 409 (conflict)- Generic conflict
  • 412 (Precondition Failed)- Precondition failed ( Such as the conflict when executing condition update )
  • 415 (unsupported media type)- The received expression is not supported
  • 500 (internal server error)- General error response
  • 503 (Service Unavailable)- The service is currently unable to process the request

PUT

  • Unsafe but idempotent
  • Create a resource with the instance number managed by the client
  • Update resources by replacing
  • If not modified , Update resources ( Optimism lock )
  • 200 (OK)- If an existing resource is changed
  • 201 (created)- If a new resource is created
  • 301(Moved Permanently)- Resources URI Has been changed
  • 303 (See Other)- other ( Such as , Load balancing )
  • 400 (bad request)- A bad request
  • 404 (not found)- Resource does not exist
  • 406 (not acceptable)- The server does not support the required representation
  • 409 (conflict)- Generic conflict
  • 412 (Precondition Failed)- Precondition failed ( Such as the conflict when executing condition update )
  • 415 (unsupported media type)- The received expression is not supported
  • 500 (internal server error)- General error response
  • 503 (Service Unavailable)- The service is currently unable to process the request

DELETE

  • Unsafe but idempotent
  • Delete resources
  • 200 (OK)- The resource has been deleted
  • 301 (Moved Permanently)- Resources URI Has been changed
  • 303 (See Other)- other , Such as load balancing
  • 400 (bad request)- A bad request
  • 404 (not found)- Resource does not exist
  • 409 (conflict)- Generic conflict
  • 500 (internal server error)- General error response
  • 503 (Service Unavailable)- The server is currently unable to process the request

“ client / Form of server ”, Built on a distributed system , Communicate over the Internet , With high delay (high latency)、 High concurrency .

How to develop software used in Internet Environment .

RESTful framework , Is the most popular Internet software architecture . Represent layer state transformation

It has a clear structure 、 Meet the standard 、 Easy to understand 、 Easy to expand , So more and more websites are using .

R resources :

REST The name of " Represent layer state transformation " in , Omit the subject .“ The presentation layer " In fact, it means " resources ”(Resources) Of " The presentation layer ".

** So-called " resources ", It's an entity on the Internet , Or a specific information on the Internet .** It can be a piece of text 、 A picture 、 A song 、 A service , In a word, it is a concrete reality . You can use one URI( Uniform resource locator ) Pointing to it , Each resource corresponds to a specific URI. To get this resource , Visit its URI Can , therefore URI It becomes the address or unique identifier of each resource .

R The presentation layer representation:

" resources " It's an information entity , It can have many external forms . We put " resources " In the form of , It's called it " The presentation layer "(Representation)

URI Entities that represent resources only , Does not represent its form . Strictly speaking , Some of the last ".html" Suffixes are unnecessary , Because this suffix means format , Belong to " The presentation layer " Category , and URI It should only represent " resources " The location of . Its concrete manifestation , belong HTTP The requested header information uses Accept and Content-Type Field assignment , These two fields are right " The presentation layer " Description of .

State transformation State Transfer:

Internet communication protocol HTTP agreement , It's a stateless protocol . It means , All States are saved on the server side . therefore , If the client wants to operate on the server , By some means , Let it happen on the server side " State transformation "(State Transfer). And this transformation is based on the presentation layer , So is " Represent layer state transformation ".

The means used by the client , Can only be HTTP agreement . say concretely , Namely HTTP In the agreement , Four verbs for operation :GET、POST、PUT、DELETE. They correspond to four basic operations :GET Used to obtain resources ,POST Used to create a new resource ( Can also be used to update resources ),PUT Used to update resources ,DELETE Used to delete resources .

Summarize what is RESTful framework :

(1) every last URI Represents a resource ;

(2) Between client and server , A layer of expression that conveys this resource ;

(3) Client through four HTTP Verb , Operate on the server-side resources , Realization " Represent layer state transformation ".

版权声明
本文为[process1212]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230519446035.html