Learning Express
- Part 1: Request and Response
- Part 2: HTTP Request Methods
- Part 3: Dynamic Routing
- Part 4: RESTful Design
Express is a popular minimalist web framework for Node.js.
RESTful Design
Representational State Transfer (REST) is a software architectural style using uniform URI resources with stateless operations. It maps common CRUD tasks as HTTP request methods.
CRUD | HTTP Request Method |
Create | POST |
Read | GET |
Update | PUT |
Delete | DELETE |
Creating a RESTful design is based on determining core objects and their relationships. For a project based on organizing books, for example, a URI component might be “/book/:id” to return a single resource or “/genre/:topic” to return a collection of books based on their genre.
Resource manipulation through representations
Designs following the RESTful style should allows all valid CRUD operations for existing resources via the representation provided. In other words, having a representation, a URI scheme, should allow all valid operations within the permission context.
The use of the words “permission context” are important because it could be the case that clients have limited or varying permissions. Not all clients may be allowed to delete or change recourses, for example.
Self-descriptive messages
An important consideration when using RESTful design is to also include “self-descriptive messages” for all end-routes. Any parameter passed to a URL should return some form of feedback, even if only an error message.