- What are the HTTP Methods in RESTful API and when would you use each of these?
- What does this HTTP Status codes represent?
- 1xx
- 2xx
- 3xx
- 4xx
- 5xx
- What is the difference between the following response functions?
- res.send()
- res.json()
- res.render()
- What are the appropriate status code for the following:
- Status Code OK
- Status Code Bad Request
- Status Code Unauthorized
- Status Code Forbidden
- Status Code Not Found
- Status Code Internal Server Error
Created
December 13, 2023 12:12
-
-
Save halitbatur/d50bd5c96d8d5b84fa3b179f71194131 to your computer and use it in GitHub Desktop.
Rest discussion questions
Team members Names: Muna Al Haj Eid, Jafar Bino, Yara Jaber, Lin dabul.
- The main HTTP methods used in RESTful APIs are:
- GET: Used to retrieve data from a server. GET requests should only retrieve data and not modify it. It's commonly used for fetching information like fetching a specific resource or a collection of resources.
- POST: Used to send data to the server to create a new resource. POST requests are used for creating new resources on the server. For example, when submitting form data or creating a new record in a database.
- PUT: Used to update an existing resource or create a resource if it doesn't exist. PUT requests usually require sending the entire resource with the updated data to the server. It replaces the existing resource with the new one provided.
- PATCH: Similar to PUT, but instead of sending the entire resource, PATCH is used to apply partial modifications to a resource. It's used when you want to update specific fields of an existing resource.
- DELETE: Used to remove a resource from the server. DELETE requests are used for deleting a specific resource identified by a URL.
- OPTIONS: Used to describe the communication options for the target resource. It specifies which HTTP methods are allowed for a specific resource.
- HEAD: Similar to GET but only retrieves the headers of the response without the actual body content. It's used to get metadata about a resource without getting the resource itself, useful for checking the validity or existence of a resource.
When to use each method: - GET: Use when you want to retrieve data from the server.
- POST: Use when you want to create a new resource on the server.
- PUT: Use when you want to update an existing resource or create a new resource if it doesn't exist.
- PATCH: Use when you want to partially update an existing resource.
- DELETE: Use when you want to remove a resource from the server.
- OPTIONS: Typically used for discovering what HTTP methods and other options are supported by a web server.
- HEAD: Use when you need metadata or headers of a resource without fetching the entire content.
- Status Codes:
- 1xx: Informational - Request received, continuing process.
- 2xx: Success - The action was successfully received, understood, and accepted.
- 3xx: Redirection - Further action needs to be taken in order to complete the request.
- 4xx: Client Error - The request contains bad syntax or cannot be fulfilled.
- 5xx: Server Error - The server failed to fulfill a valid request.
- The difference between the response functions
- res.send() is a method that can sending a response. The method will be like res.send([body]) the body could be:( Buffer, String, Object, Array). this method will automatically sets the Content-Type for ex: passing a string, it will set the Content-Type header to text/html
- res.json() this method is same as res.send() but it used specifically to sends a JSON response. It sets the Content-Type header to application/json and also it converts non-objects to json.
- res.render() this methoth is used to render a view and sends the rendered HTML string to the client. It will compile the template, inserts locals there, and creates html output out of those two things.
- The appropriate status code:
- Status Code OK (200)
- Status Code Bad Request (400)
- Status Code Unauthorized (401)
- Status Code Forbidden (403)
- Status Code Not Found (404)
- Status Code Internal Server Error (500)
Room 6: Belal, Mahmoud, Hammam, Baraa.
What are the HTTP Methods in RESTful API and when would you use each of these?
- GET: Requests a representation of the specified resource. Requests using GET should only retrieve data.
- HEAD: Asks for a response identical to that of a GET request, but without the response body.
- POST: Used to submit an entity to the specified resource, often causing a change in state or side effects on the server.
- PUT: Replaces all current representations of the target resource with the request payload.
- DELETE: Requests to delete the specified resource.
- CONNECT: Establishes a tunnel to the server identified by the target resource.
- OPTIONS: Used to describe the communication options for the target resource.
- TRACE: Performs a message loop-back test along the path to the target resource.
- PATCH: Used to apply partial modifications to a resource.
What does this HTTP Status codes represent?
- 1xx - Informational: The server has received the request and is continuing the process
- 2xx - Successful: The request was successful and the browser has received the expected information
- 3xx (Redirection): You have been redirected and the completion of the request requires further action
- 4xx (Client Error): The website or the page could not be reached, either the page is unavailable or the request contains bad syntax
- 5xx (Server Error): While the request appears to be valid, the server could not complete the request
What is the difference between the following response functions?
- res.send(): function basically sends the HTTP response. it accepts a single parameter body. The body parameter can be a String or a Buffer object or an object or an Array. It returns an Object.
- res.json(): function sends a JSON response. This method sends a response (with the correct content-type) that is the parameter converted to a JSON string using the JSON.stringify() method. (Sends data in JSON format and ends the request.)
- res.render(): used to render a view and sends the rendered HTML string to the client.
What are the appropriate status code for the following:
- Status Code OK: 200
- Status Code Bad Request: 400
- Status Code Unauthorized: 401
- Status Code Forbidden: 403
- Status Code Not Found: 404
- Status Code Internal Server Error: 500
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Team : Feda, Dana, hakeema, Mohmmad
Q1: Post : create , Get : read and retrieve data , put : Update/Replace , patch : Update/Modify delete : delete.
Q2 : 1XX: Information responses(EX: 102 : This code indicates that the server has received and is processing the request, but no response is available yet.
) , 2XX Successful responses , 3XX Redirection messages , 4XX : Client error responses, 5XX : Server error responses
Q3:Res.send(): where the body can be any of the following: Buffer, String, an Object and an Array.
is a general-purpose function for sending various types of responses.
Res.json():It sends a JSON response. This method is identical to res.send() when an object or array is passed, but it also converts non-objects to json., it's also is specifically designed for sending JSON responses.
res.render() is used when you want to render and send HTML views using a template engine.
Q4- 1- 200 , 2- 400 3-401 4 - 403 5-404 6- 500