reading-notes

My reading notes journal for Code Fellows

View the Project on GitHub

*Readings: CRUD

Status Codes Based On REST Methods

  1. In your own words, describe what each group of status code represents:

100’s = The status codes are there to inform us. It lest the client know the request has been received. 200’s = These codes are success codes and lets the client know the request has been accepted. 300’s = The codes let us know codes have been redirected and that the request is not available. 400’s = There errors are client side and that the client’s request was not accept to the server. 500’s = These are server side codes and the let us know that the server has has too much going on or is behind.

  1. What is a status code 202? It’s the basic status code to tell the client everything went good. Since we don’t create endpoint accessible resource when creating an access token, we can use 200 as a status for that action. 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.
  2. What is a status code 308? 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. This is the right code if the resource will now be available at a new URL and the client should directly access it via the new URL in the future. The current endpoint can’t control the clients’ behavior after the request and a subsequent redirect if the resource URL changes again have to be issued from the new URL.
  3. What code would you use if an update didn’t return data to a client? 204 No Content.
  4. What code would you use if a resource used to exist but no longer does? 500
  5. What is the ‘Forbidden’ status code? 403 Forbidden.

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

  1. Why do we need to pull our MongoDB database string out of our server and put it into our .env? It allows the server to connect to the MongoDB database.
  2. What is middleware? Middleware provides services and allows the application to have capabilities outside of our OS.
  3. What does app.use(express.json()) do? It parses requests that are incoming with JSON. Code the runs before the server gets passed but before it gets to our route. Lets our server accept json as a body.
  4. What does the /:id mean in a route? It means its a parameter that we can access by typing req.params.id. It gives us access to whatever it passes into it after the first /.
  5. What is the difference between PUT and PATCH? Patch updates on what the individual thing user passes us if we use put it updates all the information a user passes us.
  6. How do you make a default value in a schema? default: Date.now for example.
  7. What does a 500 error status code mean? It means that there is an error on the server. It’s the server fault.
  8. What is the difference between a status 200 and a status 201? 201 means an object was successfully created. 200 still means everything was successful but 201 is much more specific.

References

https://www.moesif.com/blog/technical/api-design/Which-HTTP-Status-Code-To-Use-For-Every-CRUD-App/ https://www.youtube.com/watch?v=fgTGADljAeg&list=PLZlA0Gpn_vH_uZs4vJMIhcinABSTUH2bY&index=4 https://expressjs.com/en/api.html#:~:text=express.json(%5Boptions%5D)&text=This%20is%20a%20built%2Din,header%20matches%20the%20type%20option.