Status Codes Based On REST Methods

My reading notes for Code Fellows


Status Codes Based On REST Methods

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

100’s = Informational codes that inform the user about why the request is having issues, and often that the server will be trying to get them what they require.

200’s = The request has been accepted, or is an acceptable request

300’s = Redirection codes that tell the user that the information they requested is no longer available at that endpoint.

400’s = Client error codes, meaning that the user should check for any syntax errors or other wrong information on their part.

500’s = The server is having an issue. The client may wish to try again once the aserver issue has been resolved.

What is a status code 202? In case of asynchronous processing of a request (202), this doesn’t mean the request was successfully processed only that it met all validation requirements at the time of sending.

What is a status code 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.

What code would you use if an update didn’t return data to a client? 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.

What code would you use if a resource used to exist but no longer does? 410 Gone - This is like 404 but we know that the resource existed in the past, but it got deleted or somehow moved, and we don’t know where.

What is the ‘Forbidden’ status code? 403 Forbidden - The client has authorized or doesn’t need to authorize itself, but still has no permissions to access the resource.

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? We do so because it acts as the key to open the door when the digital handshake occurs

What is middleware? The middleware in node. js is a function that will have all the access for requesting an object, responding to an object, and moving to the next middleware function in the application request-response cycle.

What does app.use(express.json()) do? express. json() is a method inbuilt in express to recognize the incoming Request Object as a JSON Object.

What does the /:id mean in a route? This is an express middleware of some kind. I don’t understand anything more about it yet.

What is the difference between PUT and PATCH? PUT is a method of modifying resource where the client sends data that updates the entire resource. PATCH is a method of modifying resources where the client sends partial data that is to be updated without modifying the entire data.

How do you make a default value in a schema?

You can specify a default value for an item using the default keyword. When a data doesn’t have a corresponding value, the value of this keyword will be used instead to do the validation checks. This keyword is not mandatory and the value of this keyword can be anything.

What does a 500 error status code mean? Internal Server Error: This means that the server encountered something unexpected that prevented it from fulfilling the request. In some ways, it’s an ambiguous error. The server doesn’t know exactly what’s wrong, but it knows something is wrong.

What is the difference between a status 200 and a status 201? The 200 status code is the most common returned. It means that the request was received and understood and is being processed. A 201 status code indicates that a request was successful and as a result, a resource has been created (for example a new page).