Enterprise Java Development@TOPIC@

Chapter 106. REST-like Concepts

Resources, URIs, Methods, Content, and Status Codes

106.1. REST
106.2. "REST-like"
106.3. HTTP Protocol embraced
106.4. Resource
106.5. Uniform Resource Indentifiers (URIs)
106.6. Methods
106.6.1. Method Safety
106.6.2. Idempotent
106.7. Response Codes
106.8. Links
106.9. Summary
  • Architectural Style for creating web services

  • Provide interoperability between computer systems on the Internet

  • Uses a uniform and predefined set of stateless operations

  • Defined in 2000 by Roy Fielding in his doctoral dissertation that was also used to design HTTP 1.1 [11]

  • An address (of varying detail) to access a particular resource

  • Technically, URIs can be either URNs or URLs

    • Uniform Resource Name [13]

      • Resource identity

      • Globally unique

      • Example:

        urn:info.ejava.products:1
        <core xmlns="urn:activemq:core">
        
    • Uniform Resource Locator [14]

      • Resource's location on a network

      • Contains protocol information -- "how to get it"

      • Example:

        http://127.0.0.1/jaxrsInventoryWAR/api/products/1
        https://127.0.0.1/jaxrsInventoryWAR/api/products/1
        ftp://127.0.0.1/info.ejava.products:1
        
    • Commonly -- URIs are a partial URL

      • Commonly lack protocol and physical location

      • Relative to some point in the application

      • Example:

        /jaxrsInventoryWAR/api/products/1
        /api/products/1
        products/1
        
  • Example resource collection URI

    /api/products
    /api/categories
    /api/customers
    /api/todo_lists
    
  • Example individual resource URIs (with mandatory path {parameter}s

    /api/products/{productId}
    /api/categories/{categoryId}
    /api/customers/{customerId}
    /api/customers/{customerId}/sales
    
  • Example nested resource URIs

    /api/products/{productId}/instructions
    /api/categories/{categoryId}/products
    /api/customers/{customerId}/purchases
    /api/todo_lists/{listName}/todo_items
    
  • URIs may express variable parameters

    • Use query parameters for optional variables

      http://127.0.0.1:8080/jaxrsInventoryWAR/api/categories?name=&offset=0&limit=0
      
    • Nested path parameters may express mandatory variables

      http://127.0.0.1:8080/jaxrsInventoryWAR/api/products/{id}
      http://127.0.0.1:8080/jaxrsInventoryWAR/api/products/1
      id=>1
      
  • URI naming conventions

    • Use a plural name for resource collections

      /api/todo_lists
      
    • Use an ID below the plural resource collection to refer to a specific resource

      /api/todo_lists/{listName}
      

REST-like applications likely stop at providing standard links in HTTP headers

POST http://localhost:8080/ejavaTodos/api/todo_lists
{"name":"My First List"}
=>Created/201
Location: http://localhost:8080/ejavaTodos/api/todo_lists/My%20First%20List
Content-Location: http://localhost:8080/ejavaTodos/api/todo_lists/My%20First%20List


[11] "Architectural Styles and the Design of Network-based Software Architectures. Doctoral dissertation", Roy Thomas Fielding, University of California, Irvine, 2000 HTML Version