Reading-Notes

Reading

Status Codes Based On REST Methods

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

What is a status code 202?

“Accepted” It tells the client that the request was valid and it is processing and that will finish some time in the future. Often used for asyncronous processing.

What is a status code 308?

“Permanent Redirect” If the URL is changing it informs the client where the information will be found in the future.

What code would you use if an update didn’t return data to a client?

204 no content

What code would you use if a resource used to exist but no longer does?

If it’s not just a redirect, and I don’t know where to find said resource 410- gone.

What is the ‘Forbidden’ status code?

403

Videos

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

Why do we need to pull our MongoDB database string out of our server and put it into our .env?

Having entered the .env into the gitignore putting the MongoDB string in the .env protects it from being public.

What is middleware?

Code that runs when the server gets a request but before the information gets passed through the routes.

What does app.use(express.json()) do?

It allows the server to accept json as a body inside a post element.

What does the /:id mean in a route?

The colon specifies that the route is looking for the parameter ‘id’.

What is the difference between PUT and PATCH?

Patch replaces only what it is given, put replaces everything.

How do you make a default value in a schema?

Each SchemaType that you define (you can read more about them in the model definition chapter ) can have a default value.

Default values are applied when the document skeleton is constructed. This means that if you create a new document (new MyModel) or if you find an existing document (MyModel.findById), both will have defaults provided that a certain key is missing. https://mongoosejs.com/docs/2.7.x/docs/defaults.html

What does a 500 error status code mean?

Server error.

What is the difference between a status 200 and a status 201?

200 is “sucess” while 201 is more specific to say “you’ve successfully created an object”