RESTful Web Services


Urls
- Short, Meaningful, Predictable, Readable urls
- Nouns, not verbs
- Lower case
- Use hypens rather than spaces or underlines
- Use a plural path for collections
- Put individual resources under the plural collection path.
- Favor hackable urls over direct urls.

Idempotent
stateless
versioned
PATCH - to update parts of a resource, update one or more fields as opposed to all fields.
Define SLA

actions
POST /transactions
from=1&to=2&amount=500.00

REST is a term coined by Roy Fielding in his Ph.D. dissertation to describe an architecture style of networked systems.
REST is an acronym standing for Representational State Transfer, REST defines a set of architectural principles by which you can design Web services that focus on a system's resources, including how resource states are addressed and transferred over HTTP by a wide range of clients written in different languages.
REST is a key design idiom that embraces a stateless client-server architecture in which the web services are viewed as resources and can be identified by their URLs.
Web service clients use a small globally defined set of remote methods, such as GET, Put, POST, and DELETE to access and manipulate the resource. REST is an analytical description of the existing web architecture, and thus the interplay with HTTP protocol appears seamlessly.
REST isn’t protocol-specific, but they usually mean REST over HTTP.
The HTTP methods such as GET, PUT, POST, DELETE are the verbs that the developer can use to describe the necessary create, read, update, and delete (CRUD) actions to be performed.
REST has had such a large impact on the Web that it has mostly displaced SOAP- and WSDL-based interface design because it's a considerably simpler style to use.
Motivation for REST
The motivation for REST was to capture the characteristics of the Web which has made the Web successful. 
REST is an Architectural Style, not a standard.
REST Web Services Characteristics
Here are the characteristics of REST:
  • REST is a pull-based interaction style client-server model.
  • Named and addressable resources
         The key abstraction of information and data in REST is a resource, and the system is comprised of resources which are named using a URI. (Uniform Resource Identifier)
  • A uniform, constrained interface
         All resources are manipulated with a generic interface (e.g., HTTP GET, POST, PUT, DELETE).
         Advantages:

    1. Familiarity
    2. Interoperability
    HTTP is a very ubiquitous protocol. Most programming languages have an HTTP
    1. client library available to them.
  • Communicate stateless
        Stateless applications are easier to scale to meet increasingly high performance demands; each request from client to server must contain  all the information necessary to understand the request.
        Stateless services are less complicated to design, write, and distribute across load-balanced servers. A stateless service performs better and shifts most of the responsibility of maintaining state to the client application. 
        Advantages:
    1. Scalability
                  We can reuse the rich and configurable caching semantics defined in HTTP, such as client browser cache, procy etc.
  • Hypermedia As The Engine Of Application State (HATEOAS)
    Let your data formats drive state transitions in your applications.
One of the uses of hypermedia and hyperlinks is composing complex sets of information from disparate sources. Hyperlinks allow us to reference and aggregate additional data without bloating our responses.
with each request returned from a server it tells you what new interactions you can do next, as well as where to go to transition the state of your applications.
     Miscs 
  • Cache: A caching infrastructure can be leveraged for performance; GET method can normally be cacheable.
  • Use HTTP methods explicitly, RESTful Web service uses Put, GET, POST, and DELETE to create, retrieve, change and delete a resource.
  • Expose directory structure-like URIs, REST Web services normally use directory structure-like URIs,
http://www.myservice.org/discussion/topics/{topic}
http://www.myservice.org/discussion/{year}/{day}/{month}/{topic}
This kind of URI is straightforward, predictable, and easily understood.
    * Interconnected resource representations - the representations of the resources are interconnected using URLs, thereby enabling a client to progress from one state to another. We can put hyperlinks within resource representations to enable clients to drill down for more information, and/or to obtain related information
    * Layered components - intermediaries, such as proxy servers, cache servers, gateways, etc, can be inserted between clients and resources to support performance, security, etc.
Principles of REST Web Service Design
1. The key to creating Web Services in a REST network (i.e., the Web) is to identify all of the conceptual entities that you wish to expose as services.
2. Create a URL to each resource. The resources should be nouns, not verbs.
3. Categorize your resources according to whether clients can just receive a representation of the resource, or whether clients can modify (add to) the resource. For the former, make those resources accessible using an HTTP GET. For the later, make those resources accessible using HTTP POST, PUT, and/or DELETE.
4. All resources accessible via HTTP GET should be side-effect free. That is, the resource should just return a representation of the resource. Invoking the resource should not result in modifying the resource.
5. No representation should be an island, put hyperlinks within resource representations to enable clients to drill down for more information, and/or to obtain related information.
6. Design to reveal data gradually. Don't reveal everything in a single response document. Provide hyperlinks to obtain more details.
7. Specify the format of response data using a schema. For those services that require a POST or PUT to it, also provide a schema to specify the format of the response.
8. Describe how your services are to be invoked using either a WADL document, or simply an HTML document.
RESTful Support in JAX-WS
The Java API for XML Web Services (JAX-WS) provides full support for building and deploying RESTful web services, The API was developed through JSR 224, JSR-311.


Resources:
RESTful Java with Jax-RS (Animal Guide)
RESTful Web services: The basics
RESTful Web Services
Representational State Transfer (REST) - Roy Fielding

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)