Book description
In todayâ??s market, where rival web services compete for attention, a well-designed REST API is a must-have feature. This concise book presents a set of API design rules, drawn primarily from best practices that stick close to the Webâ??s REST architectural style. Along with rules for URI design and HTTP use, youâ??ll learn guidelines for media types and representational forms.
REST APIs are ubiquitous, but few of them follow a consistent design methodology. Using these simple rules, you will design web service APIs that adhere to recognized web standards. To assist you, author Mark Massé introduces the Web Resource Modeling Language (WRML), a conceptual framework he created for the design and implementation of REST APIs.
- Learn design rules for addressing resources with URIs
- Apply design principles to HTTPâ??s request methods and response status codes
- Work with guidelines for conveying metadata through HTTP headers and media types
- Get design tips to address the needs of client programs, including the special needs of browser-based JavaScript clients
- Understand why REST APIs should be designed and configured, not coded
Publisher resources
Table of contents
- Dedication
- Preface
- 1. Introduction
-
2. Identifier Design with URIs
- URIs
-
URI Format
- Rule: Forward slash separator (/) must be used to indicate a hierarchical relationship
- Rule: A trailing forward slash (/) should not be included in URIs
- Rule: Hyphens (-) should be used to improve the readability of URIs
- Rule: Underscores (_) should not be used in URIs
- Rule: Lowercase letters should be preferred in URI paths
- Rule: File extensions should not be included in URIs
- URI Authority Design
- Resource Modeling
- Resource Archetypes
-
URI Path Design
- Rule: A singular noun should be used for document names
- Rule: A plural noun should be used for collection names
- Rule: A plural noun should be used for store names
- Rule: A verb or verb phrase should be used for controller names
- Rule: Variable path segments may be substituted with identity-based values
- Rule: CRUD function names should not be used in URIs
- URI Query Design
- Recap
-
3. Interaction Design with HTTP
- HTTP/1.1
-
Request Methods
- Rule: GET and POST must not be used to tunnel other request methods
- Rule: GET must be used to retrieve a representation of a resource
- Rule: HEAD should be used to retrieve response headers
- Rule: PUT must be used to both insert and update a stored resource
- Rule: PUT must be used to update mutable resources
- Rule: POST must be used to create a new resource in a collection
- Rule: POST must be used to execute controllers
- Rule: DELETE must be used to remove a resource from its parent
- Rule: OPTIONS should be used to retrieve metadata that describes a resource’s available interactions
-
Response Status Codes
- Rule: 200 (“OK”) should be used to indicate nonspecific success
- Rule: 200 (“OK”) must not be used to communicate errors in the response body
- Rule: 201 (“Created”) must be used to indicate successful resource creation
- Rule: 202 (“Accepted”) must be used to indicate successful start of an asynchronous action
- Rule: 204 (“No Content”) should be used when the response body is intentionally empty
- Rule: 301 (“Moved Permanently”) should be used to relocate resources
- Rule: 302 (“Found”) should not be used
- Rule: 303 (“See Other”) should be used to refer the client to a different URI
- Rule: 304 (“Not Modified”) should be used to preserve bandwidth
- Rule: 307 (“Temporary Redirect”) should be used to tell clients to resubmit the request to another URI
- Rule: 400 (“Bad Request”) may be used to indicate nonspecific failure
- Rule: 401 (“Unauthorized”) must be used when there is a problem with the client’s credentials
- Rule: 403 (“Forbidden”) should be used to forbid access regardless of authorization state
- Rule: 404 (“Not Found”) must be used when a client’s URI cannot be mapped to a resource
- Rule: 405 (“Method Not Allowed”) must be used when the HTTP method is not supported
- Rule: 406 (“Not Acceptable”) must be used when the requested media type cannot be served
- Rule: 409 (“Conflict”) should be used to indicate a violation of resource state
- Rule: 412 (“Precondition Failed”) should be used to support conditional operations
- Rule: 415 (“Unsupported Media Type”) must be used when the media type of a request’s payload cannot be processed
- Rule: 500 (“Internal Server Error”) should be used to indicate API malfunction
- Recap
-
4. Metadata Design
-
HTTP Headers
- Rule: Content-Type must be used
- Rule: Content-Length should be used
- Rule: Last-Modified should be used in responses
- Rule: ETag should be used in responses
- Rule: Stores must support conditional PUT requests
- Rule: Location must be used to specify the URI of a newly created resource
- Rule: Cache-Control, Expires, and Date response headers should be used to encourage caching
- Rule: Cache-Control, Expires, and Pragma response headers may be used to discourage caching
- Rule: Caching should be encouraged
- Rule: Expiration caching headers should be used with 200 (“OK”) responses
- Rule: Expiration caching headers may optionally be used with 3xx and 4xx responses
- Rule: Custom HTTP headers must not be used to change the behavior of HTTP methods
- Media Types
- Media Type Design
- Recap
-
HTTP Headers
-
5. Representation Design
- Message Body Format
-
Hypermedia Representation
- Rule: A consistent form should be used to represent links
- Rule: A consistent form should be used to represent link relations
- Rule: A consistent form should be used to advertise links
- Rule: A self link should be included in response message body representations
- Rule: Minimize the number of advertised “entry point” API URIs
- Rule: Links should be used to advertise a resource’s available actions in a state-sensitive manner
- Media Type Representation
- Error Representation
- Recap
- 6. Client Concerns
- 7. Final Thoughts
- A. My First REST API
- About the Author
- Copyright
Product information
- Title: REST API Design Rulebook
- Author(s):
- Release date: October 2011
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781449310509
You might also like
book
Mastering API Architecture
Most organizations with a web presence build and operate APIs; the doorway for customers to interact …
book
Clean Architecture: A Craftsman's Guide to Software Structure and Design
Building upon the success of best-sellers The Clean Coder and Clean Code, legendary software craftsman Robert …
book
Clean Code: A Handbook of Agile Software Craftsmanship
Even bad code can function. But if code isn’t clean, it can bring a development organization …
video
Understanding APIs and RESTful APIs Crash Course
This course will help you understand what APIs and RESTful APIs are and how they work. …