Spring Web MVC implements restful web Service

Source: Internet
Author: User
Tags soap representational state transfer

An introduction:

When it comes to Web service, you're sure to associate soap with the fact that Web service is now reminiscent of restful, because the RESTful Web service has become popular and reused, more and more prevalent than bulky soap, So what is RESTful Web Service. Rest English is all called the representational state Transfer, translated to Chinese, which is characterized by status transitions, is a software architecture style, and Rest key principles are:

Define IDs for all "things"

Link all things together

Using standard methods

Multiple representations of resources

No State communication

RESTful Web Services is a Web service that uses HTTP and follows the rest principles. It is defined from three areas of resources:

URI, such as: http://example.com/resources/.

Web service accepts and returns the type of Internet media, such as: Json,xml.

A series of request methods that the WEB service supports on the resource (for example, post,get,put or delete).


The typical application of HTTP request method in restful Web service

Resources

Get

Put

POST

DELETE

A URI for a set of resources, such as http://example.com/resources/

Lists the URI and details of each resource in the resource group (optional).

Replaces the current entire set of resources with a given set of resources.

Create/Append a new resource in this group of resources. This action often returns the URL of the new resource.

Deletes an entire set of resources.

URI of a single resource, such as http://example.com/resources/142

Gets the details of the specified resource, in a format that allows you to choose a suitable network media type (e.g. XML, JSON, etc.)

Replaces/creates the specified resource. and append it to the appropriate resource group.

The specified resource is treated as a resource group, and a new element is created/appended under it to subordinate to the current resource.

Deletes the specified element.


Two SPRINGMVC support for the RESTful WEB service:

1. Map the URI and HTTP request methods to the Java processing method and return the Java method processing results to the HTTP requester (corresponding resource definitions I and III).

@RequestMapping

This is the most important annotation that is used to handle HTTP request address mappings, which can be used on classes or methods where all response requests in a class are represented as parent paths, and in spring, a controller class typically handles a resource, So each controller class will add @requestmapping annotations.

Common Properties:

Value: Specify the address of the request

Method: Specifies the method type of the request, get, POST, put, delete, and so on

Params: Specifies that some parameter values must be included in the request to allow the method to handle

1 2 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.