RESTful design principles and examples (development of front and rear interface)

Source: Internet
Author: User
Tags soap

Reference post: http://www.cnblogs.com/artech/p/restful-web-api-02.html

Wikipedia: Https://zh.wikipedia.org/wiki/REST

There are currently three main types ofWeb Servicesimplementation scenario, because the rest mode and the complexSoapand theXml-rpcMore and more Web services are beginning to be designed and implemented in restful style compared to more concise. For example,Amazon.comprovide close-to-rest-style Web services for book search;YahooThe Web services provided are also rest-style.

key points and standards

It is important to note that rest is a design style rather than a standard. Rest is often based on the use of Http,uri, and XML as well as the HTML of these existing widely popular protocols and standards.

    • A resource is specified by a URI.

    • Operations on resources include acquiring, creating, modifying, and deleting resources that correspond exactly to the get, POST, put, and Delete methods provided by the HTTP protocol.

    • Manipulate resources by manipulating their representations.

    • The expression of a resource is either XML or HTML, depending on whether the reader is a machine or a person, a client software that consumes a Web service, or a Web browser. Of course, it can be any other format.

Requirements for rest
    • Client and server architecture

    • The connection protocol has no State

    • Ability to use the cache mechanism to improve performance

    • Hierarchical system

    • Code Required-Javascript (optional)

about states

You should be aware of the status of the application and the status of the Connection Agreement. HTTP connections are stateless (that is, the information for each connection is not logged), and rest transports contain all the state information for the app, which can significantly reduce the consumption of duplicate requests for HTTP connections.

apply to Web services

The restful design-style Web API is called   RESTful API It is defined from the following three resources:

    • Intuitive short resource address: URI, for example: http://example.com/resources/ .

    • Transmitted resources: Web Services accept and return the Internet media types, such as: Json,xml , YAML , and so on.

    • Action on a resource: a series of request methods (such as post,get,put or delete) supported by the Web service on that resource.

The following table lists the typical uses of the HTTP request method when implementing the RESTful API.

[1] Typical application of the HTTP request method in RESTful APIs
resources get put post delete
http://example.com/resources/ lists the   URI, and the details of each resource in the resource group (the latter is optional). Replace with a given set of resources . The current entire set of resources. Create/Append A new resource. This operation often returns the URL of the new resource. Delete   the entire group of resources.
http://example.com/resources/142 get   Specify the details of the resource, format can choose a suitable network media type (such as: XML, JSON, etc.) replace/create   Specifies the resource. and append it to the appropriate resource group. Create/Append A a new element that is subordinate to the current resource. Delete   The specified element.

put and DELETE methods are idempotent methods. The Get method is a security method   (no modification to the server side, so of course, idempotent).

Unlike SOAP-based Web services, RESTful Web services do not have a "formal" standard [2]. This is because rest is a schema, and soap is just a protocol. While rest is not a standard, there are various other criteria (such as http,url,xml,png, etc.) that can be used when implementing restful Web services.

implementation Examples [ edit ]

For example, a simple Web Store app,

List all products,

GET http://www.store.com/products

Render a product,

GET http://www.store.com/product/12345

Order Purchase,

POST http://www.store.com/order<purchase-order> <item> ... </item1></purchase-order>
Benefits of Rest
    • More efficient use of caching for faster response times

    • The stateless nature of the communication itself allows different servers to process different requests in a series of requests, increasing the scalability of the server

    • Browser as a client to simplify software requirements

    • Rest has less software dependencies than other mechanisms superimposed on the HTTP protocol

    • No additional resource discovery mechanism required

    • Long-term compatibility in the evolution of software technology is better

All input and output by default is in JSON format. One exception: The parameter to the GET request is a URL parameter
Error codes all use HTTP standard error codes, see HTTP standard status codes

To modify a user:

Url:post/mm/v1/crm/customer/[customer ID]
Input:
Parameter Name argument type description required default value limit
Name string Customer name is
Interface_person String Docking person name is
Interface_phonenumber string Docking person phone is
Interface_email String Docking Person mailbox is

Output:
Parameter Name argument type description Sample value
ID int Customer ID 10001
Name string Customer Name Bank
Interface_person string Docking person name Xiaoming
Interface_phonenumber string Docking person phone 12345678
Interface_email string docking person email [email protected]
Create_time Date Client creation time 2015-04-01 12:34:56

Get all editable permissions
Url:get/mm/v1/crm/permission
Input
Output
An array. Each element represents an editable permission entry in the following format
Parameter Name argument type description Sample value
ID int permission ID 1
Name string permission names DEMO APP

Delete User

Url:delete/mm/v1/crm/customer/[customer ID]
Input: None
Output:
Parameter Name argument type description Sample value
ID int successfully deleted customer ID 10001

RESTful design principles and examples (development of front and rear interface)

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.