CRUD
Index
Home
Status Codes Based on REST Methods
Build a REST API with Node.js, Express, and mongoDB
Status Codes Based on REST Methods
- In your own words, describe what each group of status code represents:
100’s = Reads the header and tells the client its request has been received.
200’s = Success! 300’s = Redirects. Data has moved or isn’t present anymore. 400’s = Client errors. Mainly invalid requests 500’s = Server erros. Either too many requests or unreachable proxy. - What is a status code 202?
- Accepted - If the deletion is asynchronous and takes some time, which is the case in distributed systems, it can be appropriate to return this code with some information or URL to tell the client when it will be deleted.
- What is a status code 308?
- Permanent Redirect - 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.
- 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, and mongoDB
- Why do we need to pull our MongoDB database string out of our server and put it into our .env?
- Eventually the server will need to be run on something that is not localhost.
- What is middleware?
- Code that run but before a request gets passed to your route
- What does
app.use(express.json())do?- Lets our server accept json as a body inside of an element.
- What does the
/:idmean in a route?- Provides access to whatever is typed in after the first slash (/).
- What is the difference between
PUTandPATCH?Putupdates all of the information for the subscriber at once.Patchonly updates what the user passes.
-
How do you make a default value in a schema?
const subscriberSchema = new mongoose.Schema({ name: { type: String, required: true } subscriberToChannel { type: String, required: true } subscribeDate: { type: Date, required: true, default: Date.now } }) - What does a
500error status code mean?- There is an error on the server.
- What is the difference between a status
200and a status201?200means everything was successful.201means successfully created an object.