- HTTP (HyperText Transfer Protocol)
- GET request to get data
- REpresentational State Transfer
- a pattern for designing Web APIs
- resources
- identified by URL
- passed as JSON payload of request or response
- collections
- sets of resources
- Will be using on Levels 0-2 of Richardson Maturity Model
- Level 0: Single URI
- Level 1: Separate URIs for resources
- Level 2: Use of HTTP methods
- JavaScript Object Notation
- Standard format for representing an object as text
- Subtext of JS
- Parsers and formatters available in many languages
- JSON.parse()
- JSON.stringify()
- "Object" means POJSO (Plain Old JavaScript Object)
- no classes or types
- A REST request is handled by code which defines an endpoint
- Complete API often requires many endpoints
- Requests are routed by matching URL patterns
/orders/:id
- Read
- GET
- Create
- POST
- Update
- PUT
- Delete
- DELETE
- Update (partial)
- PATCH (apply a patch (edit))
- To get a collection:
GET /orders
- To get a single resource:
GET /orders/9011
- To create a resource:
POST /orders
- Body of request contains data for new resource
- Response contains new resource with ID
- To delete a resource:
DELETE /orders/9011
- Response is empty but resulting state of backend is that resource is deleted
- To update a resource:
PUT /orders/9013
- Body of request contains new data for resource
- Response contains updated resource
- 1xx: Informational
- 2xx: Success
- 200: OK
- 201: Created
- 204: No Content
- 3xx: Redirection
- 301: Moved Permanently
- 4xx: Client Error
- 400: Bad Request
- 401: Unauthorized (really unauthenticated)
- 403: Forbidden
- 404: Not Found
- 405" Method Not Allowed
- 5xx: Server Error
- 500: Internal Server Error
- 501: Not Implemented
- 503: Service Unavailable
- Runs in NodeJS
- Web server that we can extend using JavaScript
- Initialization steps
- Create an app
- Add your routes
- Call
app.listen()
- Route includes
- HTTP method
- URL pattern
- may include patterns
- Handler function