Java Development Restful__java

Source: Internet
Author: User
Tags representational state transfer
First of all, what is rest?

Rest is literally called the representational state Transfer, translated into a presentation layer status transfer, but generally in translation, a resource is preceded by the resource representational state Transfer, that is, the resource performance layer state transfer. Employing words is: The client through the HTTP request, the server-side resources to operate, implementation of the "performance layer (using HTTP verbs to promote server-side resources) state changes." Two. What is restful?

RESTful is meant to be restful, or designed to conform to the rest architecture, so to understand restful you need to know rest.

Three. Why do we use the restful style to develop interfaces?

Look at the traditional way of designing interfaces:

Add an employee: HTTP://WWW.DEMO.CN/FINANCE/EMPLOYEE/CREATEEMP

Delete an employee: HTTP://WWW.DEMO.CN/FINANCE/EMPLOYEE/DELETEEMP

Modify an employee: HTTP://WWW.DEMO.CN/FINANCE/EMPLOYEE/UPDATEEMP

Get Employee List: HTTP://WWW.DEMO.CN/FINANCE/EMPLOYEE/LISTEMP

Now we find out: a very simple demand-generating problem:

1. Each operation requires a separate URL to operate, because we need to reflect the action of the employees in the URL.

2. Will produce a large number of URLs, very inconvenient interface maintenance and document maintenance

3. If there are different ways of responding, we may need additional parameters, or even different URLs to describe

4. The request parameter is included in the request address and cannot be targeted for caching

If we use the RESTful style interface, then we can do the following:

Add one employee: POST Http://www.demo.cn/finance/employee

Delete an employee: delete Http://www.demo.cn/finance/employee

Modify an employee: PATCH Http://www.demo.cn/finance/employee

Get list of employees: getting Http://www.demo.cn/finance/employee

It can be found that we give the different meanings of these requests through HTTP requests, and the action design and examples are as follows:


Here's a simple practice where we can use the open source Yapi to help us manage interfaces and test:











Related Article

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.