Current location - Education and Training Encyclopedia - Graduation thesis - What's the difference between REST webservice and ordinary servlet?
What's the difference between REST webservice and ordinary servlet?
One: the basic knowledge of Web services

A simple web service is just a web page waiting to be requested and processed. The easier way to understand is the internet.

Services can turn an application into a basic WEB-based request and processing application. Two common types

The Web service processing method is:

A. the way based on WSDL/SOAP

B. Rest mode

Mode A is orthodox, and the client call must first obtain the WSDL file, and then generate the calling API.

Need to use it. Is not the point I want to say, the basic call process is as follows:

Mode B is a Rest mode, and the design principle of Rest Web Service is based on CRUD, which supports four operations.

Don't be:

Get–Get information/request information content, which is used by most browsers to get information.

Postposition-adding information content and displaying the previous information content can be regarded as an insertion operation.

Put-–updates the information content, which is equivalent to update.

Delete-deleting information content can be regarded as deletion.

If the HTTP protocol itself is the most Restful in design principle, then the Rest mode is simpler and more convenient.

Agree with the HTTP protocol, which supports the CRUD operation well. Because of this, starting from WEB2.0, based on

Restful Web services are increasingly becoming the first choice.

Second, understand the RestfulStyle.

The full name of Rest is RepresentationalState Transfer, which may seem a bit strange on the surface.

HTTP protocol itself is a stateless protocol, by setting the request header fields Connection: keep-alive and.

At the same time, set the expiration time for control. In fact, Rest-style WebService are stateless and have the least benefits.

There are two kinds:

1. Better load balancing, reducing the burden on the server.

2. Faster client response and less unnecessary status check.

The rise of Restful style benefits from Internet giants such as Google and Facebook, which provide a large number of Restful-based.

The styles of web services, from Google Maps to weather forecast to translation, are also true of domestic Internet giants Tencent and Sina Weibo.

Publish their own web services to attract more developers to join their camp. Rest not only satisfies the basic CRUD

In addition to the design principles, the following conventions should be followed:

The 1. resource operation can be realized by description, that is, presentation.

2. The message itself is stateless and self-describing (the transmission supports XML and JSON).

3. You can send and receive multiple representations.

Rest style architecture principle:

1. Client server mode

2. Stateless protocol transmission

3. Support caching

4. Unified interface definition

5. Hierarchical system design

In this way, the Web service API of Rest is published, and its changes will not affect the client program and implementation. If your system

What if the Rest-style architecture cannot be applied? Redesign a new architecture and extend the Rest style architecture. but

CRUD is a must for most systems and applications in the world.

Three. Rest and HTTP

As mentioned above, HTTP protocol is probably the most Rest-style protocol, and HTTP 1. 1 is a principle of protocol design.

Need to implement Rest style. So there is no doubt that HTTP GET, POST, PUT and DELETE are the best proofs.

But whether Rest style can be applied to other protocols and system design, the answer is yes, and one is the best.

Examples show that POP3 protocol supports reading data records, querying records, updating records and deleting records.

What a perfect Rest protocol.

Existing HTTP protocol applications:

1. browser client (you surf the Internet every day, either IE or Chrome, or other browsers, you know)

2. Instant messaging, MSN/Skype support

3. Various content management systems

4. Blog system and microblog client application.

5. You can add/?

Detailed explanation of Rest message:

1. It is no different from the HTTP URI we know now, and Google Static Map is a good example.

Just add different parameters to URL to get different map contents.

2. It can support any type of data transmission, similar to information transmission based on XML and JSON.

It is more desirable to transmit text content and structured text content.

3.SOAP and XML-RPC have strict message format restrictions, while rest has no message format requirements. Customer caller

Shit!

The advantages of Rest-style Web services are obvious. One advantage is that it simplifies customer calls, unlike WSDL.

That kind of trouble. Thereby reducing the learning cost of third-party developers and shortening the learning curve. Conducive to the promotion and popularization of services

Moreover, it attracts more users and brings potential commercial benefits.

In software as a service (SaaS- software as a service) and software as a platform (PasS- platform

As a service) has an important position and application. This is the Rest that those Internet giants are interested in.

One of the reasons Greg is interested.

Four: Rest style architecture

Can Rest style be used in non-web system design and architecture/? The answer is yes, Rest can be used in any

In system design, Rest is not a technology in essence, but an architectural principle, which can of course be used to construct non-.

Network system. The bigger the system, the more style it should be like Rest, which is the successful architecture.

Object-oriented programming in WEB

JavaScript libraries such as ExtJS and KendoUI (based on JQuery) have been very convenient to get content from URL.

Updating data, front-end design tends to be more detailed hierarchical design, not just MVC. client

Programmers should pay more attention to the user experience in the foreground, because these frameworks are well encapsulated and extensible.

More and more language programming such as JavaScript has introduced the concept and practice of object-oriented. It is no exaggeration to say, for example

Today's JavaScript programming is fundamentally different from that of ten years ago.