Versions Compared

Key

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

Table of Contents
outlinetrue
REST

Introduction

REST is not a standard, but a Web application development architectural style, which can be understood as a design pattern. REST-based HTTP, URI, XML and widely popular these existing protocols and standards, along with REST, HTTP protocol to obtain a more correct use. SOAP and WSDL-based Web services, REST model provides a more concise compared to realization.

...

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

NameDescription
specificationscheme://[host]:[port]/path?queryString
schemeProtocol term , typically http or https
host(DNS) Host Name or IP address
portPort
pathResource address, logical Hierarchy Use '/ 'delimited
 ?Resources used to separate address and query string of symbols
queryStringQuery string, scope information ampersand method to separate the query conditions separated by commas orderly scope information separated by semicolons no information about the scope of the order

Resource Address Description

...

Resource Path Information

ServiceTypeServiceNameServiceVersionPathInfo
openoapicatalogv1/servicetemplates
openoapicatalogv1/servicetemplates/{serviceTemplateId}
oepnouilogv1/info/syslogs
oepnouilogv1/statisticinfo/syslogs

Absolute URI and Relative URI

...

Cacheable ways to obtain a response to previous requests from the cache at a mid-tier caching.
MethodSafeIdempotentCachableREST Use
GETYesYesYesQuery Resource
HEADYesYesYes
POSTNoNoNoCreate Resource
PUTNoYesNoUpdate Resource
DELETENoYesNoDelete Resource
OPTIONSYesYesNo
PATCHNoNoNoUpdate Resource
TRACEYesYesNo

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.

FunctionResource Address
Add/CreatePOST/books
PUT/books/{id}
DeleteDELETE/books
Modify/UpdatePUT /books
Query AllGET /books
Primary key queryGET /books/{id}
GET /books?id=123
Paging scope queryGET /books?start=0&size=10 
GET /books/01,2012-02,2015
GET /books/hadoop;language=scala;type=xxx

Resource Address Design Specification

...

  • API Service
  • Content service , static pages and js, css and other resources
Functionscheme://[host]:[port]/pathqueryString
API Service Specification[[host\]]:[port]/openoapi/[Service Name]/v[Version Number]/[Resource]/queryparam1=xxx, queryparam2=xxx
Content Service Specification[[host\]]:[port]/openoui/[Content of the resource]/index.htmlNone

Note: The version number before lowercase letter 'v'

For example:

Functionscheme://[host]:[port]/pathqueryString
log API Service[[host\:\[port\]/openoapi/log/v1/loginfo/syslogs]]starttime=xxxx
Endtime=xxxx
log Content Service[[host\:\[port\]/openoui/log/]]
alarm API Service[[host\:\[port\]/openoapi/fm/v1/alarms]]
alarm Content Service[[host\:\[port\]/openoui/fm/]]

Use path variables to express the resource hierarchy

...

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.


Status CodeRequest TypeMeaningException class
200 OK[GET]Server successfully returned the data requested by the user, the operation is idempotentResponse.Status.OK
201 CREATED[POST/PUT/PATCH]?Create or modify user data successfulResponse.Status.CREATED
202 ACCEPTED[*]?Represents a request has been queued into the background (asynchronous task)Response.Status.ACCEPTED
204 NO CONTENT[DELETE]Delete user data successfulResponse.Status.NO_CONTENT
400 BAD REQUEST[POST/PUT/PATCH]?Request issued by a user error, the server does not operate create or modify data, the operation is idempotentBadRequestException
401 Unauthorized[*]Indicates that the user is not authenticated (token, username, password error)NotAuthorizedException
403 Forbidden[*]Indicates that the user is authenticated (401 errors are relatively), but access is prohibited. it used for unauthorizedForbiddenException
404 NOT FOUND[*]Request issued by the user is directed to a nonexistent record, the server does not operate, the operation is idempotent.NotFoundException
406 Not Acceptable[GET]Format requested by the user not available (such as a user request JSON format, but only XML format).NotAcceptableException
410 Gone[GET]Resource requested by the user is permanently deleted and can not be obtainedResponse.Status.GONE
422 Unprocesable entity[POST/PUT/PATCH]When you create an object, a validation error occurs.
500 INTERNAL SERVER ERROR[*]Server error occurs, the user will be unable to determine whether the request is sent successfullyInternalServerErrorException

Discussion