Class Twelve Notes
REST
HTTP Codes
100’s = informational, tells the client that the header part of the request has been received and the server will try to comply
200’s = SUCCESS! Request accepted.
- 202: in the case of async request, it informs the client that the request met all validation requirements
- 204: no content, the code for updates that don’t return data to the client
300’s = redirect, the request no longer available at the expected location
400’s = client error
- 403: forbidden: the client has no permission to access the resource
- 404: the resource used to exist but no longer does
500’s = Server error
Build REST API
- Pulling our MongoDB database string out of our server and put it into our .env makes it easier to manage if the link changes from local to cloud environment
- Middleware is what connects modules together
app.use(express.json()) allows the server to accept JSON
/:id: gives user access to whatever they put in after the id, it only allows a single router access
- The difference between
PUT and PATCH is PATCH only passes whatever the user input is, while PUT will update all subsriber’s info rather than just one
- To make a default value in a schema, by adding a
default property to the model
- Status 200 means “everything ok”, 201 is “created”
Back to main page
References