What is REST? What is RESTful?

REST (REpresentation State Transfer) architectural style describes a network system refers to a set of architectural constraints and principles.

RESTful refers to the application or to meet these design constraints and principles.

RESTful service is an architectural pattern, it's lightweight web services, play a native HTTP protocol GET, PUT, POST, DELETE.

REST is not always the right choice. As a method of designing Web services become popular, this method relies on proprietary middleware (such as an application server) is less than the method based on SOAP and WSDL. 

 

The key is how to use REST resource abstraction, abstraction more precisely, the application of REST, the better.

REST service key principles:

1. All object to an ID

2. Connect objects together

3. Using standard methods

4. Resource multiple representations

5. the stateless

REST can achieve is a decoupling method, let us achieve these architectural features: performance, scalability, simplify, modify, scalability 

In J2EE we can use RS-JAX, Dropwizard ... 
DOTNET platform can use the Web API, WCF, servicestack, nancyfx 

 

The most important principles of REST Web applications is that the interaction between the client and the server between requests are stateless. Each request from a client to the server the request must contain the information necessary for understanding. If the server is restarted at any point in time between the request, the client will not be notified. In addition, the stateless request may be answered by any available server, which is very suitable for such a cloud computing environment. The client may buffer data to improve performance.

On the server side, the application status and functions can be divided into a variety of resources. Resource entity is an interesting concept, it is exposed to the client. Examples of resources are: application objects, database records, algorithms, and so on. Each resource use URI (Universal Resource Identifier) ​​to get a unique address. All resources share a unified interface to transfer state between the client and the server. Using standard HTTP methods such as GET, PUT, POST, and DELETE. Hypermedia is the engine of application state, represented by a hyperlink Internet resources.

Another important principle is that REST layered system , which means that components can not understand the components other than the intermediate layer with which it interacts. By limiting the knowledge of the system in a single layer, you can limit the complexity of the overall system, promoting the independence of the underlying.

When the REST architectural constraints of the application as a whole, will generate a large number of applications can be extended to the client. It also reduces the latency interaction between the client and the server. Unified interface, simplifying the overall system architecture, to improve the visibility of interactions between subsystems. REST simplifies the client and server implementations.

 

 

REST contrast RPC 

Understand what is what is REST, we'll look at the implementation of RESTful. Recently, the use of RPC-style architecture built SOAP-based Web services for SOA has become the most common method. RPC-style Web service client to an envelope filled with data (including the methods and parameter information) to the server via HTTP. The server opens the envelope and execute the specified method parameters passed. The results of the method and packaged into an envelope as a response back to the client. The client receives the response and opened the envelope. Each object has its own unique approach and RPC-style Web service exposes only one URI's, URI represents a single endpoint. It ignores most features and supports only HTTP POST method.

Due to the lightweight and the nature of HTTP data transmitted through direct, RESTful Web service method has become the most common alternative. You can use a variety of languages ​​(such as Java programs, Perl, Ruby, Python, PHP and Javascript [including Ajax]) to achieve the client. RESTful Web services are usually automatically by the client or on behalf of the user application access. However, the simplicity of this service enables users to interact directly with them, using their Web browser to build a GET URL and read the contents returned.

In REST-style Web services, each resource has an address. Target resource itself is a method call, the list of methods is the same for all resources. These methods are standard methods, including HTTP GET, POST, PUT, DELETE, and may also include HEADER OPTIONS.

In RPC-style architecture, the focus is on methods, but in the REST architectural style, the focus is on the resource - using the standard method of operation and retrieve the pieces of information (represented in the form used). Resource representation hyperlinks interconnection representation in.

Leonard Richardson and Sam Ruby introduces the term REST-RPC hybrid architecture in their book RESTful Web Services in. REST-RPC hybrid Web service does not use envelopes packaging methods, parameters and data, but directly transfer data via HTTP, which is REST-style Web services are similar. But it does not use standard HTTP methods of operation resources. It is part of the URI in the HTTP request method of storing information. Several well-known Web services, such as Yahoo's Flickr API and the del.icio.us API use this hybrid architecture.

Of RESTful realization: Java RESTful Web services framework

There are two Java frameworks can help build RESTful Web services. erome Louvel and Dave Pawson development Restlet (see Resources) is lightweight. It implements a variety of resources for RESTful system, said that the concept of connectors and media types and the like, including Web services. In Restlet frame, both the client and server components. Communicate with each other through the connector assembly. The most important class is the abstract class Uniform frame and the Restlet concrete subclass, sub-class of this class is dedicated, such as Application, Filter, Finder, Router and Route. These subclasses can be processed together with authentication, filtering, security, data conversion and routes incoming requests to corresponding resources and other operations. Resource class of generating a representation of the client.

JSR-311 is a Sun Microsystems specification for the development of RESTful Web services can define a set of Java API. Jersey JSR-311 is a reference implementation.

JSR-311 provides a set of comments related classes and interfaces can be used to display Java objects as Web resources. This specification assumes that the underlying network protocol is HTTP. It provides a clear using annotations and corresponding mapping between the URI resource, a mapping between the HTTP method, and a method of Java objects. API supports a wide range of HTTP entity content types, including HTML, XML, JSON, GIF, JPG and so on. It will also provide the required plug-in function to allow the use of standard method by adding other types of applications.

RESTful implementation: building multi-tier architecture RESTful Web services

RESTful Web services and dynamic Web applications are similar in many respects. Sometimes they provide the same or very similar data and functions, although the different types of clients. For example, the online classified e-commerce sites to provide users with a browser interface to search, view and order products. If you provide Web services for companies, retailers and even individuals can automatically place an order, it will be very useful. As with most dynamic Web applications, Web services can benefit from a separation of concerns in the multi-tier architecture. Business logic and data can be shared by the client and automatically GUI client. The only difference is the nature of the presentation layer and the intermediate layer of the client. Moreover, separation of service logic from the data access can be achieved in a database independence and the ability to plug various types of data storage.

Figure 1 shows the automation clients, including Java and scripts written in various languages, these languages ​​include Python, Perl, Ruby, PHP, or command-line tools such as curl. Running in a browser and as a consumer service Ajax RESTful Web operation, Flash, JavaFX, GWT, blog and wiki belong to this category, because they represent the user to run an automated style. Automated Web Services in the Web tier client sends an HTTP response to the Resource Request Handler. Stateless client request contains information method, i.e. POST, GET, PUT and DELETE in the head, which in turn maps to a corresponding operation of the Resource Request Handler resources. Each request contains all the necessary information, including credentials Resource Request Handler for processing the request.

After receiving a request from a Web service client, Resource Request Handler request service from the business logic layer. Resource Request Handler to identify all the conceptual entities, these entities will be disclosed as a resource, and assign a unique URI for each resource. However, the conceptual layer entity does not exist. They exist in the business logic layer. You can use Jersey or other frameworks (such as Restlet) realize Resource Request Handler, it should be lightweight, to delegate a lot of responsibility work to the business layer.

On Ajax and RESTful Web services are essentially complementary. They can take advantage of a large number of Web technologies and standards, such as HTML, JavaScript, browser objects, XML / JSON and HTTP. Of course, you do not need to buy, install or configure any of the major components to support front-end interaction between Ajax and RESTful Web services. RESTful Web services provides a very simple API for Ajax to handle the interaction between the server resources.

FIG 1 Web browsers as client GUI front layer representing the generated HTML Browser Request Handler provides a display function. Browser Requester Handler can use the MVC model (example JSF, Struts or Spring are Java's). It accepts requests from the browser, request service from the business logic layer, it generates and responds to the browser. Representation for the user to use the display in the browser. Represents not only contains the content, the display also includes properties, such as HTML and CSS.

Multi-tier Web application environment map

Business rules can be concentrated to the business logic layer, which layer acts as intermediate layer represents a layer between the data and the data access layer switching. Data to the presentation layer in the form of domain objects or object values. Decoupled from the business logic in the Browser Request Handler and Resource Request Handler helps promote code reuse, and to achieve a flexible and scalable architecture. In addition, because the future can use the new REST and MVC framework, they are easier to achieve, without rewriting the business logic layer.

Interactive data access layer provides data storage layer may be used DAO design pattern or the object - relational mapping solution (e.g., Hibernate, OJB or the iBATIS) implemented. As an alternative, the business layer and data access layer component can be implemented as EJB components, and with the support EJB container, the container can facilitate assembly lifecycle management persistence, transactions, and resource allocation. However, this requires compliance with a Java EE application servers (such as JBoss), and may not be processed Tomcat. That the effect of the different layers of data storage technology, separate data access code from the business logic. Data access layer can also act as an integration point connections to other systems, can be a client to other Web services.

Data storage layer includes database systems, LDAP servers, file systems, and enterprise information systems (including legacy systems, transaction processing systems and enterprise resource planning systems). Using this architecture, you can begin to see the power of RESTful Web services, which can be flexibly into a unified API to any enterprise data storage, which open vertically data to Web applications with user-centric, and automated batch report script.

What is REST: Conclusion

REST describes an architectural style of the interconnected system (such as Web applications). REST constraint application as a whole, will generate a simple, scalable, efficient, safe, reliable architecture. Because it is simple, lightweight and direct transfer via HTTP characteristic data, RESTful Web services to become one of the most promising alternative to SOAP-based services. Multi-layer structure for web services and dynamic Web applications can be re-usability, simplicity, scalability, and clean separation of components of response. On Ajax and RESTful Web services are essentially complementary. Developers can easily use Ajax and RESTful Web services to create rich interfaces together.

 

 

Guess you like

Origin blog.csdn.net/fengdijiang/article/details/89015815