Software Development - Web Programming

REST Web Services and Microservices

URL Description
Applying RESTful design to an entire website? The partially answers the question of what happens if your page is made up of several other resources - what is the form of the main resource you are getting from the server? In this case you can think of the resource as being in document-oriented form, even though the parts may be stored separartely. How the serves of the resource is transparent to the client which consumes the response as a document with several parts which can be represented as an Express template (basically a View).
Beautiful REST & JSON APIs

  • Scalability
  • Generality
  • Independence (language independent)
  • Latency (Caching)
  • Security (built into HTTP)
  • Encapsulation (decoupling)

Designing a Beautiful REST + JSON API (another talk)

Beautiful REST + JSON APIs

Building Micro Services (REST APIs) for your app
Coding Skills 101: How to call REST APIs from Python and jQuery
Designing URL Schemes and REST Interfaces
Fault Tolerance in High Volume, Distributed System

In an earlier post by Ben Schmaus, we shared the principles behind our circuit-breaker implementation. In that post, Ben discusses how the Netflix API interacts with dozens of systems in our service-oriented architecture, which makes the API inherently more vulnerable to any system failures or latencies underneath it in the stack. The rest of this post provides a more technical deep-dive into how our API and other systems isolate failure, shed load and remain resilient to failures.

Google I/o 2010 - How Google builds APIs
HATEOAS 101 - Opinionated Introduction to REST API Style - Webcast The Constraints of REST (Roy Fielding)
  1. Client-server
  2. Stateless server
  3. Cache
  4. Uniform interface
    • Identification of resources
    • Manipulation of resources through representations
    • Self-descriptive message
    • Hypermedia as the engine of application state (HATEOAOS)
  5. Layerd System
  6. Code-On-Demand
How to use the REST API from Java
Intro to REST - Joe Gregorio
Jersey 2.16 User Guide (Java) How to create Client and Server REST services and access them from Java.
Keynote: Microservices by Martin Fowler
Micro Services at Netflix
Microservices - Martin Fowler Characteristics of Microservices
  1. Componentization via services
  2. Organized around business capbilities
  3. Products not Projects
  4. Smart endpoints and dumb pipes
  5. Decentralized Governance
  6. Decentralized Data Management
  7. Infrastructure Automation
  8. Design for failure
  9. Evolutionary Design
Microservices Architecture

You are developing a server-side enterprise application. It must support a variety of different clients including desktop browsers, mobile browsers and native mobile applications. The application might also expose an API for 3rd parties to consume. It might also integrate with other applications via either web services or a message broker. The application handles requests (HTTP requests and messages) by executing business logic; accessing a database; exchanging messages with other systems; and returning a HTML/JSON/XML response.

Microservices and Monoliths - Is There a Third Way?
Microservices... or die!
NGINX - How to Adopt Microservices
ProgrammableWeb.com
REST API concepts and examples
REST Anti-patterns
REST Nirvana with Microservices
REST Web Services 01 - Introduction REpresentational State Transfer
REST Web Services 02 - REST and HTTP
REST Web Services 03 - Resource URIs
REST Web Services 04 - Collection URIs
REST Web Services 05 - HTTP Methods
REST Web Services 06 - Method Idempotence
REST Web Services 07 - REST Response
REST Web Services 08 - HATEOAS
REST Web Services 09 - The Richardson Maturity Model
REST Web Services 10 - What Is JAX RS?
REST Web Services 11 - Setting Up
REST Web Services 12 - Understanding the Application Structure
REST Web Services 13 - Creating a Resource
REST Web Services 14 - Returning XML Response
REST Web Services 15 - Installing a REST API client
REST Web Services 16 - Building Service Stubs
REST Web Services 17 - Accessing Path params
REST Web Services 18 - Returning JSON Response
REST Web Services 19 - Implementing POST Method
REST Web Services 20 - Implementing Update and Delete
REST Web Services 21 - Implementing ProfileResource
REST Web Services 22 - Pagination and Filtering
REST Web Services 23 - The Param Annotations
REST Web Services 24 - Using Context and BeanParam annotations
REST Web Services 25 - Implementing Subresources
REST Web Services 26 - Sending Status Codes and Location Headers
REST Web Services 27 - Handling Exceptions
REST Web Services 28 - Using WebApplicationException
REST with Java (JAX-RS) using Jersey - Tutorial

This tutorial explains how to develop RESTful web services in Java with the JAX-RS reference implementation Jersey.

In this tutorial Eclipse 4.4 (Luna), Java 1.6, Tomcat 6.0 and JAX-RS 2.0 (with Jersey 2.11) is used

REST-Ful API Design with Spring (2013)

Very good intro to REST

REpresentational State Transfer

  • An architectural style for designing distributed systems
  • Not a standard, but rather a set of constraints
  • Not tied to HTTP, but associated most commonly with it

  • URI's identify resources
  • HTTP verbs describe a limited set of operations that can be used to manipulate a resource
    1. GET
    2. DELETE
    3. PUT
    4. POST
  • Headers help describe the messages

GET

  • Retrieve Information
  • Must be safe and idempotent - can have side effects, but since the user doesn't expect them they shouldn't be critical to the operation of the system.
  • GET can be conditional or partial
    • If-Modified-Since
    • Range
  • Example: GET /games/1

DELETE

  • Request that a resource be removed
  • The resource doesn't have to be removed immediately
  • Removal may be a long running task
  • Example: DELETE /games/1

PUT

  • Requests that the entity passed by stored at the URI
  • Can be used to create a new entity or modify an existing one, however, creation is uncommon as it allows the client to select the id of the new entity.
  • Example: PUT /games/1/doors/2
  • Put doesn't have to replace everything, it can be partial. { "status":"SELECTED" }

POST

  • Requests that the resource at a URI do something with the enclosed entity
  • What that something is could be almost anything
    • Create
    • Modify
  • The major difference between POST and PUT are what resource the request URI identifies.
  • Example: POST /games

Example of creating a game with REST

Create a Game

  • Well-known entry point
  • Doesn't require any input other than requesting that a game be created
  • Needs to return us a URI of the newly created game
  • Example: POST /games (creates a game)

List the current state of all Doors

  • Needs to return us a collection that represents the state of all doors in the game.
  • Design doesn't have 'Door1', 'Door2', 'Door3', just three doors
  • Example: GET /games/0/doors
    [{"status": "CLOSED"}, {...},{,,,}]

Select a Door

  • There is no HTTP verb "SELECT", so how do we represent the selection of a door?
  • Request a resource mutation that leaves the resource in desired state.
  • Example: PUT /games/1/doors/2
    {"status": "SELECTED"}

Open a Door

  • Like select, we want to request a mutation to the desired state
  • Since the same (or same type of) resource is being modified, we re-use the same payload.
  • Example: /games/1/doors/3
    {"status": :"OPEN"}

List the final state of the Game

  • Needs to return an object that represents the state of the game
  • Example: GET /games/0
    {"status": "WON"}

Destroy the Game

  • No input required
  • No output required
  • Example: DELETE /games/0

Status Codes

Broad Categories

  • 1XX: Informational
  • 2XX: Success
  • 3XX: Redirection
  • 4XX: Client Error
  • 5XX: Server Error

Success Status Codes (2XX)

  • 200 OK
    • Everything worked
  • 201 Created
    • The server has successfully created a new resource
    • Newly created resource's location returned in the Location header
  • 202 Accepted
    • The Server has accepted the request, but it is not yet complete
    • A location to determine the request's current status can be returned in the Location header

Client Error Status Codes (4XX)

  • 400 Bad Request
    • Malformed Syntax
    • Should not be repeated without modification
  • 401 Unauthorized
    • Authentication is required
    • Includes a WWW-Authenticate header
  • 403 Forbidden
    • Server has understood, but refuses to honor the request
    • Should not be repeated without modification
  • 404 Not Found
    • The server cannot find a resource matching a URI
  • 406 Not Acceptable
    • The server can only return response entities that do not match the client's Accept header
  • 409 Conflict
    • The resource is in a state that is in conflict with the request
    • Client should attempt to rectify the conflict and then resubmit the request
REST: I don't Think it Means What You Think it Does by Stefan Tilkov This presentation was recorded at GOTO Amsterdam 2014
RESTful API Design - Second Edition Slides for the Talk
Restify for Node.js
Roy Fielding's PhD Dissertation on REST (PDF)

Architectural Styles and the Design of Network-based Software Architectures

SpringOne2GX 2014 (video)

As data-driven applications become ubiquitous, the services that provide the data are proliferating. As teams become responsible for more and more of these services, it becomes critical that they be designed and implemented in a way that is as lightweight as possible. This session will cover how to design micro-services as RESTful APIs and implement them with minimal code using Spring Boot. It will focus on API design using REST and HATEOAS, with live coding progressing from a tweet-length implementation all the way to a full-fledged app running in the cloud.