Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
outlinetrue
REST

Introduction

REST(Representational State Transfer) is not a standard but a Web application development architectural style, which can be understood as a design pattern. REST is based on some widely used existing protocols and standards such as HTTP, URI, XML, etc. Along with REST, HTTP protocol is used in a  more correct way. Compared with SOAP and WSDL-based Web services, REST model provides a more concise solution.

URI

Introduction

A Uniform Resource Identifier (URI) is a string of characters used to identify a resource.

Description

Part Description

URI generally consists of three parts

  • Named mechanism for accessing resources
  • Storage resource host name
  • The name of the resource itself, represented by the path. Typically, this string scheme (named URI namespace identifier) at the beginning of the following syntax: [scheme:] scheme-specific-part. URI scheme and the beginning of the colon, Scheme uppercase / lowercase letters beginning, followed by the empty or more uppercase / lowercase letters, numbers, plus, minus and dot. Colon and the scheme scheme-specific-part separated, and the scheme-specific-part syntax and semantics (meaning) is determined by the namespace URI.

A typical URI in the table below, including the protocol name, host name, port services, and other resources to address and query string:

...

Resource Address Description

Resource address is divided into ServiceType, ServiceName, Service Version, PathInfo four parts.

http(s)://[hostname][:port]/[ServiceType]/[ServiceName]/[Service Version]/[PathInfo]

ServiceType

Service Type?api and ui(UI)

ServicesName

Service Name, a globally unique

Recommended:

  • For GSO, SDNO and NFVO, service name should include the project name as well as the microservice name to ensure uniqueness, example: 'sdno-l3vpnService'
  • For O-Common and Common-Tosca, the project name is not necessary in the service name, example: 'catalog'

ServicesVersion

Service Version, requirements v + numbers, such as v1 v1.1, etc

PathInfo

Resource Path Information

...

Absolute URI and Relative URI

Absolute URI: In scheme (followed by a colon) at the beginning of the URI, for example http://www.cnn.com/index.html. It can be seen as an absolute URI reference to a resource in some way, and this way the environment is not dependent identifier appears.
Relative URI: Not in the scheme (followed by a colon) begins URI, such as articles / articles.html. You can put relative URI regarded as quoted in some way some resources, and in this way depends on the identifier appears environments.

Http Method

Operation Method

HTTP / 1.1 Protocol defines eight methods of CPC (sometimes called "action") to indicate a different mode of operation Resources Request-URI specified:

  • OPTIONS :The method returns the server request for a particular resource supports HTTP. It can also be used to send to the Web server '\ *' request to test the WEB server supports.
  • HEAD : Ask the server to ask for consistent response GET request, but the response body will not be returned. This method can be without having to transport the entire content, it can get included in the response message header meta-information.
  • GET : Make a request to a specific resource. Note: GET method should not be used to generate the "side effects" of the operation, such as modifying the resource status. Idempotent
  • POST : Submitting data to the specified resource for processing a request (such as submitting a form or uploading files). Data is included in the request body. POST requests may lead to the establishment and / or existing resources to new resource changes.
  • PUT: To upload their content to the latest specified resource location.
  • PATCH : Requests the server entity designated URI represented by the partial update. PATCH method should contain enough information for the server update requests. If the specified resource exists, the server can be updated and return the status code 200 (OK) or 204 (No Content). it similar to the processing with PUT method , if the specified resource does not exist, the server can create the resource. If the server resource is created, it should return the status code 201 (Created). If a resource to support PATCH method, then OPTIONS response Allow header can this be explained. The server can also use the Accept-Patch headers, lists media types the client can request its sending PATCH. Protocol specification recommends that media type should contain semantic information required to transfer part of the update to the server. json-patch (see https://tools.ietf.org/html/draft-pbryan-json-patch-04) is a proposed draft media types, partial updates required to support the operation expression.
  • DELETE: Requests the server to delete * Request-URI * resources identified.
  • TRACE : Requests the server returns a request it receives. The server returns a content-type of message or http context, which contains the complete request information. Clients can use the TRACE method, review the changes made to the message request message through a proxy and an intermediate layer to help diagnose problems.
  • CONNECT: Reserved for the ability to connect to the pipeline mode proxy server.

Additional Properties

Safe

Use secure HTTP method for sending the request, it does not produce any side effects from the user side. This is not to say that security measures will not cause side effects, but that the user can use this method to safely initiate the request, do not worry about inadvertently modified the system state.

Idempotent

By Idempotent issued a request for resources with multiple requests the same effect. By definition, all security methods are idempotent. Some methods are not safe, but may also be idempotent. Similar security methods, using idempotent request does not guarantee that does not produce any side effects on the server side, but unrelated to these possible side effects and users.

Cachable

Cacheable ways to obtain a response to previous requests from the cache at a mid-tier caching.

...

When a request for a resource does not support the corresponding request method, the server should return the status code 405 (Method Not Allowed); when the server does not know or does not support the corresponding request method, it shall return a status code 501 (Not Implemented).
HTTP server should implement at least the GET and HEAD methods, other methods are optional. In addition to the above-described method, a specific HTTP server can also extend custom method.

...

Resource Address Design Specification

Service Description

  • API Service
  • Content service , static pages and js, css and other resources

...

Note: The version number before lowercase letter 'v'

For example:

...

Use path variables to express the resource hierarchy

For example:

View a device information in topology:

http://127.0.0.1/api/topo/v1/resources/{Resourcelocate id}

View a user information in safe module?

http://127.0.0.1/api/sm/v1/users/{userid}

Path variable expression using punctuation non-hierarchical structure

  • If you need to express non-hierarchical order is irrelevant, use a semicolon.
  • If you need to express non-hierarchical order, use a commas.
  • If the application requires the expression of more complex structures, you can define additional punctuation and semantics, but the comma and semicolon must be used to indicate the order of relations with non-hierarchical structure.

For example:

View all link information between two nes in topology:

http://127.0.0.1/api/topo/v1/links/{ne id1};{ne id2}

View all link information from one ne to another ne in topology:

http://127.0.0.1/api/topo/V1/links/{ne id1},{ne id2}

Use query variable expression algorithm (service) input

For example:

View a system log information

http://127.0.0.1/api/log/v1/syslogs?id=101&filter=admin&count=50

Note: '&' In the URL is the only standard parameters of Http URL delimiters, do not denote any business meaning. Application needs its own resolution parameters of business meaning.

Use json variable expression algorithm (service) input

  • POST request uses json object as a parameter input, you need to put inside the body, parser body when the server response.
  • If the query parameter is too long GET request, allow POST GET equivalent use; This policy requires strict restrictions violate REST principles.

Exception Handling Design

JAX-RS2.0 defines the status code of the response javax.ws.rs.core.Response.Status and base exception class
javax.ws.rs.WebApplicationException, This exception contains the following sub-classes.

...

.

...