- 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
-
-
Save halitbatur/d50bd5c96d8d5b84fa3b179f71194131 to your computer and use it in GitHub Desktop.
Team: Hayder, Gorgees, Hassan AbuGareeb, Musab
1.
A. GET: Asking for info from a place, just getting data.
B. HEAD: Asking for info but without all the extra details.
C. POST: Sending something new to a place, usually changes stuff there.
D. PUT: Completely swapping out everything at a place with something new.
E. DELETE: Asking to remove something specific from a place.
F. CONNECT: Making a private tunnel to a specific server.
G. OPTIONS: Checking what you can do at a place, like looking at a menu.
H. TRACE: Sending a message that comes back to check if it's going the right way.
I. PATCH: Making small fixes or changes to just some parts of a thing at a place, not everything.
-
A. 1xx: Informational response
B. 2xx: Successful
C. 3xx: Redirects
D. 4xx: Client error
E. 5xx: Server error -
A: res.send() is a versatile method that sends various types of HTTP responses, such as strings, HTML, JSON, or buffers.
B: res.json() specifically sends a JSON response by converting the input into JSON format before sending it.
C: res.render() is used in templating engines (like Pug, EJS) to render a view template along with data to generate an HTML response to the client. -
A: 200
B: 400
C: 401
D: 403
E: 404
F: 500
Room 10 -> Abedalrhman Rizk , Ahmad Juma, Hasan Jabaie, Ramah Madi, Lubna Abedelkhaliq.
-
GET, POST, PUT, DELETE, PATCH
GET: The method is used for fetching details from the server and is read-only
POST: Create a new resource on the server.
PUT: This method is used to update the old/existing resource on the server
or to replace the resource.
DELETE: This method is used to delete the resource on the server.
PATCH: Partially update a resource on the server. -
1xx (Informational): Request received, continuing process.
Example: 100 Continue, 101 Switching Protocols.
2xx (Success): The action was successfully received, understood, and accepted.
Example: 200 OK, 201 Created, 204 No Content.
3xx (Redirection): Further action needs to be taken to complete the request.
Example: 301 Moved Permanently, 302 Found, 304 Not Modified.
4xx (Client Error): The request contains bad syntax or cannot be fulfilled.
Example: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found.
5xx (Server Error): The server failed to fulfill a valid request.
Example: 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable.
3 .res.send(): Sends a response of various types (string, buffer, JSON, etc.). Express infers the Content-Type.
res.json(): Sends a JSON response. It sets the Content-Type to application/json.
res.render(): Renders a view template. It is often used to render HTML templates using a view engine like EJS or Pug.
- 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 7 Dana Omar - Sanad Alshobaki - Momena Salloum - Farah Alsoqi
Question (01)
- POST: Create a new resource on the server.
- GET: Retrieve data from the server.
- PUT: Update an existing resource on the server. It replaces the entire resource.
- DELETE: Delete an existing resource on the server.
Question (02)
1xx Informational responses
2xx Successful responses
3xx Redirects
4xx Client errors
5xx Server errors
Question (03)
res.send(): Sends a basic response with optional status code and message. It can handle various data types like strings, objects, or Buffers.
res.json(): Sends a JSON response. It automatically sets the Content-Type header to application/json and converts the response to a JSON representation.
res.render(): Renders a view template using the specified template engine. It is often used in web frameworks like Express to render dynamic HTML pages using data and templates.
Question (04)
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
Team : Room 4
q1- HTTP Methods in RESTful API are POST, GET, PUT, PATCH, and DELETE.
These correspond to create, read, update, and delete (or CRUD) operations, respectively.
q2- 1xx: Informational - Indicates that the request was received and the process is continuing.
2xx: Success - Indicates that the request was successfully received, understood, and accepted.
3xx: Redirection - Indicates further action is needed to complete the request, often involving redirection to a different resource or URL.
4xx: Client Error - Indicates an issue with the client's request, such as a syntax error or unauthorized request.
5xx: Server Error - Indicates an error on the server side while trying to fulfill the client's request, not due to client actions but server issues.
q3- res.send : used to send a variety of HTTP responses, while
res.json : is specifically designed to send JSON responses
Res.render :
-
Primarily used in server-side rendering when working with template engines (like EJS )
-
Useful for generating dynamic HTML content on the server.
q4- HTTP status codes:
Status Code OK (200): Everything's good, your request succeeded.
Status Code Bad Request (400): Your request has errors, the server can't understand it.
Status Code Unauthorized (401): You need to log in or provide credentials.
Status Code Forbidden (403): Access denied, you don't have permission.
Status Code Not Found (404): The requested resource doesn't exist.
Status Code Internal Server Error (500): Something broke on the server's side; it's not your fault.
Jana AbuHaltam ,Sara Jouma , Abdullah Alawad, Ahmad Mash , Rinad Abu Qauod
Q1 : Use GET for retrieving data without modifying anything.
Use POST for creating new resources.
Use PUT for replacing an entire resource.
Use DELETE for removing a resource.
Use PATCH for making partial updates to a resource.
Q2: 1XX — Informational
2XX — Success
3XX — Redirection
4XX — Client Error
5XX — Server Error
Q3: res.send(): It can send various types of data, including plain text, HTML, or even buffers.
res.json() when you want to send JSON data.
res.render() when you are rendering dynamic HTML pages using a template engine.
Q4: 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
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
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
1- What are the HTTP Methods in RESTful API and when would you use each of these?
RESTful APIs use HTTP methods to manage resources:
GET: Retrieves data (e.g., GET /users).
POST: Creates new data (e.g., POST /products).
PUT: Replaces entire resources (e.g., PUT /users/123).
PATCH: Updates parts of resources (e.g., PATCH /users/123/email).
DELETE: Removes resources (e.g., DELETE /users/123).
Choose the method based on your desired action: read, create, update, partial update, or delete.
2- What does this HTTP Status codes represent?
1xx
Information responses: A 1xx Informational status code means that the server has received the request and is continuing the process.
2xx
Successful responses: 2xx successful – the request was successfully received, understood, and accepted.
3xx
Redirection messages: This group of status codes indicates that further action needs to be taken by the user agent in order to complete the request. The action required may be carried out by the user agent without interaction with the client only if the method used in the second request is GET or HEAD.
4xx
Client error responses: A 4xx Client Error status code means that the website or the page could not be reached and either the page is unavailable or the request contains bad syntax.
5xx
Server error responses: A 5xx code means the problem was caused by the server. With a 5xx code, the request can be present with no changes and you will get the requested result when the server has been fixed. With a 4xx code, typically the client or user has to fix an error before trying again, but there are some exceptions.
What is the difference between the following response functions?
3-1 res.send():
Usage: res.send([body])
This function is a general-purpose method for sending a response. It can be used to send various types of responses, such as plain text, HTML, or other types of data.
Example:
app.get('/', (req, res) => {
res.send('Hello, World!');
});
3-2 res.json():
Usage: res.json([body])
This function is specifically designed for sending JSON-formatted responses. It sets the Content-Type header to application/json and sends the JSON representation of the given object as the response.
Example:
app.get('/json', (req, res) => {
res.json({ message: 'Hello, JSON!' });
});
3-3 res.render():
Usage: res.render(view [, locals] [, callback])
This function is typically used with template engines (like EJS, Pug, or Handlebars) to render dynamic HTML on the server side before sending it to the client. It renders a view (template) with optional local variables.
Example (using EJS):
app.get('/template', (req, res) => {
res.render('index', { title: 'Dynamic Page' });
});
Summary:
4- What are the appropriate status code for the following:
Status Code OK
200 OK: Request successful.
Status Code Bad Request
400 Bad Request: Invalid request syntax or missing data.
Status Code Unauthorized
401 Unauthorized: Missing or invalid authentication.
Status Code Forbidden
403 Forbidden: Authorized but lacks permission for action.
Status Code Not Found
404 Not Found: Requested resource doesn't exist.
Status Code Internal Server Error
500 Internal Server Error: Something went wrong on the server.
Room 8 :
Mohamad Karbejha - Ammar Kolko - Lujain Mansour - Mohammad abdullah