reading-notes

CRUD

Reading: Status Codes

Status codes based on rest methods

  1. what each code represents
    • 100-199 = informational codes. Things that are happening
    • 200-299 = success codes
    • 300-399 = tells the client that what theyre looking for isnt in that location anymore
    • 400-499 = error codes like invalid requests or timeouts
    • 500-599 = server error codes
  2. 202 Accepted - Often used for asynchronous processing. This code tells the client that the request was valid, but its processing will finish sometime in the future. The response body should include an URL to the finished resource with some information about when it will be available, or an URL to some monitoring endpoint that tells the client when the resource is available.
  3. 308 Permanent Redirect - This tells the client to use another URL to access the resource and not use the current URL anymore. It’s helpful when we have multiple endpoints for one resource, but don’t want to implement reading from all of them.
  4. 204 No Content - A proper code for updates that don’t return data to the client, for example when just saving a currently edited document.
  5. 204 No Content - The most fitting status code for this case. It’s better to reduce traffic and simply tell the client the deletion is complete and return no response body (as the resource has been deleted).
  6. 403 Forbidden - The client has authorized or doesn’t need to authorize itself, but still has no permissions to access the resource.

Video: REST Api w/ Node.js

Build A REST API With Node.js, Express, & MongoDB - Quick

  1. the mongo db string needs to be in the .env file because it needs to be able to be different when its deployed as opposed to locally
  2. middleware is code that will get run after it gets a request but before it gets sent to the routes
  3. express.json allows our server to accept a json as a body
  4. /:id is a way to use params to target a specific thing using a route
  5. putt updates all info at once and patch only updates what the user inputs
  6. to add a defaultl value all you have to do is put default: inside the schema
  7. 500 error code means theres something wrong on the server side
  8. the difference between 200 and 201 error code is 200 is a general success message while 201 is a successful creation message.