Code 301 Class 12 Reading Notes
Status Codes Based on REST Methods
- In your own words, describe what each group of status code represents:
- 100's = Codes that give information telling the client that the header part of the request has been received and the server will try to comply with a transmission demand of the client.
- 200's = Success codes! Client request was accepted, but not successfully processed.
- 300's = A redirection code, the resource being requested is no longer there.
- 400's = Client error codes, invalid requests a client sent to a server. These include timeouts, wrong URI, missing authentication, etc. Client would need to confirm input parameters.
- 500's = Server error codes that indicate problems with overwhelmed servers or unreachable servers behind proxies, but also can be directly related to client requests that trigger error exceptions on the server. It's good to retry the same request, as these errors can be temporary or permanent.
- What is a status code 202?
Accepted
- Often used for asynchronus processing. This means that the request was valid, bit its processing will finish sometime in the future. - What is a status code 308?
Permanent redirect
-= Tells the client to use another URL to access the resource and no use the current URL anymore. - 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?
406 Not Acceptable
or410 Gone
- What is the ‘Forbidden’ status code?
403 Forbidden
Build A REST API With Node.js, Express, & MongoDB - Quick
- Why do we need to pull our MongoDB database string out of our server and put it into our .env?
- What is middleware? Code that runs when the server gets a request, and before it gets passed to our routes.
- What does
app.use(express.json())
do? Lets our server accept json, as a body instead of a post element, etc. - What does the
/:id
mean in a route? The:
means that it is a parameter, this can be accessed by typing in request. - What is the difference between
PUT
andPATCH
?PATCH
only updates what the user passes.PUT
will update all the information at once. - How do you make a default value in a schema? Please see below code and notice
default
at the end, which is a default of time to at the moment the user request information.
json new mongoose.Schema({
name: {
type: String,
required: true,
default: Date.now
}
})
- What does a
500
error status code mean? Internal Server Error - What is the difference between a status
200
and a status201
?200
is basic status code to tell client everything went good.201
signals the backend-side resource creation and come along with aLocation
header that defines the most specific URL for that newly created resource.