Skip to content

Instantly share code, notes, and snippets.

@halitbatur
Created June 25, 2024 06:47
Show Gist options
  • Save halitbatur/ad9cc9f7c27f7207a437f7ab44c74493 to your computer and use it in GitHub Desktop.
Save halitbatur/ad9cc9f7c27f7207a437f7ab44c74493 to your computer and use it in GitHub Desktop.
Rest Discussion

RESTful API Discussion Questions

  1. What are the HTTP Methods in RESTful API and when would you use each of these?
  2. What does this HTTP Status codes represent?
    • 1xx
    • 2xx
    • 3xx
    • 4xx
    • 5xx
  3. What is the difference between the following response functions?
    • res.send()
    • res.json()
    • res.render()
  4. 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
@thabiso-makolana
Copy link

Thabiso
Pumlani
Katleho

#1 HTTP Methods

  1. GET is used to retrieve data from the server. For example, fetching user details or listing all products.
  2. POST is used to send data to the server to create a new resource. For instance, creating a new user or adding a new product.
  3. PUT is used to update an existing resource on the server. An example would be updating user details or modifying a product.
  4. PATCH is used to partially update an existing resource. For example, updating the email of a user without modifying other user details.
  5. DELETE is used to remove a resource from the server. For instance, deleting a user or removing a product from the catalog.
  6. HEAD is used to retrieve the headers of a resource, similar to GET but without the body. An example would be checking if a resource exists and retrieving metadata.
  7. OPTIONS is used to describe the communication options for the target resource. For example, checking which HTTP methods are supported by a resource.

#2

  1. 1xx (Informational) indicates that the request has been received and the process is continuing. For example, 100 Continue means the initial part of the request has been received and the client can continue with the request. 101 Switching Protocols means the server is switching protocols as requested by the client.
  2. 2xx (Successful) indicates that the request was successfully received, understood, and accepted. For example, 200 OK means the request has succeeded. 201 Created means the request has been fulfilled and a new resource has been created.
  3. 3xx (Redirection) indicates that further action needs to be taken to complete the request. For example, 301 Moved Permanently means the resource has been permanently moved to a new URL. 302 Found means the resource resides temporarily under a different URL.
  4. 4xx (Client Error) indicates that the request contains bad syntax or cannot be fulfilled. For example, 400 Bad Request means the server cannot process the request due to a client error. 401 Unauthorized means authentication is required and has failed or not yet been provided.
  5. 5xx (Server Error) indicates that the server failed to fulfill a valid request. For example, 500 Internal Server Error means the server encountered an unexpected condition. 503 Service Unavailable means the server is not ready to handle the request, usually due to being overloaded or down for maintenance.

#3
res.send() is used to send a response to the client with any type of content (string, object, buffer, etc.). For example, res.send('Hello World').

res.json() is used to send a JSON response to the client. It sets the Content-Type header to application/json. For example, res.json({ message: 'Hello World' }).

res.render() is used to render a view template and send the HTML response to the client. For example, res.render('index', { title: 'Home Page' }).

#4. Status Codes
-200 OK

  • 400 Bad Request
  • 401 Unauthorized
  • 403 Forbidden
  • 404 Not Found
  • 500 Internal Server Error

@samuelthis
Copy link

@hunny-bee
@Geraldmutsw
@samuelthis

  1. GET: GET /users – Retrieve a list of users.
    POST: POST /users – Create a new user.
    PUT: PUT /users/123 – Update the user with ID 123 or create a new user with ID 123 if it doesn't exist.
    PATCH: PATCH /users/123 – Update specific fields of the user with ID 123.
    DELETE: DELETE /users/123 – Delete the user with ID 123.

  2. 1xx - Informational (100-199): These codes convey temporary information about the request's progress. For instance, a 100 Continue code
    tells the client the server has received the initial part of the request and is ready for the rest.
    2xx - Successful (200-299): This is the happy path! Codes in this range indicate the request was processed successfully. The most common
    one is 200 OK, signifying everything went smoothly.
    3xx - Redirection (300-399): These codes tell the client it needs to fetch the requested resource from a different location. A common
    example is 301 Moved Permanently, which indicates the content has been permanently moved to a new URL.
    4xx - Client Error (400-499): These codes signify issues with the request itself, typically caused by the client (like a web browser). For
    instance, a 404 Not Found code means the requested resource couldn't be located on the server.
    5xx - Server Error (500-599): These codes indicate errors originating from the server side, preventing it from fulfilling the request. A
    common example is a 500 Internal Server Error, which means something unexpected went wrong on the server.

  3. res.send(): This is the most versatile function. It can be used to send various types (string, object, buffer)
    res.json(): Sends a JSON response.
    res.render(): Renders and sends HTML from a view template

  4. 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

@Mukoni-Nemauluma
Copy link

Emihle & Konanani

  1. http methods are actions that can be performed on a resource
    GET: Requests data from a server.

POST: Submits data to be processed by a server.

PUT: Updates data on a server.

PATCH: Applies partial modifications to data on a server.

DELETE: Removes data from a server.
2. a)1xX indicates that the request is being processed. It is an informational status code
b) 2xx is a successful status code, it indicates success for example (200) means success
c) 3xx redirection status code indicting that more action is required
d) 4xx is a client error indicating client site issues for example, 400 is a bad request, 401-unauthorized, 404: requested resource does not exist
e) 5xx indicates a server-site issues
3. res.send():

Sends a basic HTTP response to the client, capable of handling plain text, HTML, or binary data.
Useful for straightforward responses without needing to specify content types explicitly.

-res.json():

Sends a JSON response to the client by converting JavaScript objects or arrays into JSON format automatically.
Typically employed in API endpoints to deliver structured data, especially in RESTful APIs.

-res.render():

Utilizes a templating engine to generate HTML content dynamically.
Integrates server-side data with a specified template to produce HTML pages.

  1. 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

@sthabiso-iv
Copy link

sthabiso-iv commented Jun 25, 2024

With @thewesss and @Siya-Faith

    • GET - Retrieves information from the API, like getting users
  • PUT - Updates an existing resource like updating user information
  • POST - Create a new resource, can also be used to get data like creating a new user
  • PATCH - Partially updates data, like updating a user's email instead of all fields
  • DELETE - Removes a resource, example being deleting a user
  1. 1xx - These are status codes that give information about the request being received
  • 2xx - These are statistical code that give information about a successful request
  • 3xx - These are redirection statuses that let you know if further action needs to be taken
  • 4xx - These are client error bad syntax errors or cannot be fulfilled
  • 5xx - These are server-side errors that occur when a server fails to fulfill a valid request
    • res.send() - It sends various types of responses, such as a string, object, buffer, or array.
  • res.json() - Sends a JSON response, it converts a JavaScript object or an array to JSON format before; sending
  • res.render() - It renders a view template and sends the rendered HTML string to the client
    • OK-200 - Request was successful
  • Bad- 400 - Server could not understand request
  • Unauthorised - 401 - The client should authenticate itself to get a response
  • Forbidden - 403 - The client does not have access rights to the content
  • Not Found - 404 - Server cannot find requested resource
  • Internal Server Error - 500 - Server encounters a situation it does not know how to handle

@Nhlanhla-advocate
Copy link

Team members: Mpilo, Troos, Advocate

  • Get - It retrieve data from the server.
  • post - It creates a new resource on the server.
  • Put - It updates an existing resource or create a resource if it does not exist.
  • Delete - It deletes an existing resource.
  • patch - It partially updates an existing resource.
  • 1xx - Information status code means that the server has received the request and is continuing the process.
  • 2xx - Status codes indicate success. They denote that the client's request was successfully received, understood and accepted by the server.
  • 3xx - These status codes indicate that further action needs to be taken by the user agent in order to fulfill the request.
  • 4xx - These status codes indicate that the request contains bad syntax or cannot be fulfilled.
  • 5xx - Status codes indicate unsuccessful, they denote that the client's request was unsuccessful.
  • res.send(): Flexible, can send various types of responses (strings, HTML, JSON, buffers, etc.).

  • res.json(): Specifically for sending JSON responses, automatically sets Content-Type to application/json.

  • res.render(): Used to render and send HTML views generated by a template engine, suitable for dynamic web pages.

  • Ok - 200
  • Bad request - 400
  • Unauthorized - 401
  • Forbidden - 403
  • Not found - 404
  • Internal server error - 500

@Gracepinkie
Copy link

Koketso
Sinethemba
Simphiwe

  1. GET:
    Purpose: Retrieve data from a server,
    .POST:
    Purpose: Submit data to the server to create a new resource.
    .PUT:
    Purpose: Update an existing resource or create a resource if it does not exist (idempotent).
    .PATCH:
    Purpose: Apply partial modifications to a resource.
    .DELETE:
    Purpose: Remove a resource.

2.1xx -Informational,
2xx Success.
3xx Redirection.
4xx Client Error.
5xx Server Error.h

  1. res.send()
    sends a response of various types like strings, objects, and arrays.

.res.json()
sends a JSON response and also converts non-objects to JSON format.

.res.render()
Renders a template with the provided data.

  1. 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 Erro: 500

@Hophneylen
Copy link

Hophneylen commented Jun 25, 2024

Lentsoana Hophney
Mpho Oganne
Lethukuthula Mkhonto

  1. Post-Create a new resource on the server.
    Delete - to remove or erase data
    Put - updating data
    Patch - Partially update an existing resource.(modify)
    Get-Retrieve data from a server

2.What does this HTTP Status codes represent?
1xx Informational
--codes indicate that the request has been received and the server is continuing to process
2xx Success
-- indicate that the request was successfully received, understood, and accepted.
3xx Redirection
-- indicate that further action needs to be taken by the user agent to fulfill the request.
4xx Client Errors
-- codes indicate that the client seems to have made an error.
5xx: Server Errors
-- status codes indicate that the server failed to fulfill a valid request.
3. res.send()
--Purpose: Send a response to the client and end the response process.
res.json()
--Purpose: Send a JSON response to the client and end the response process.
res.render()
--Purpose: Render a view template and send the resulting HTML to the client.
4.
--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

@Tumelo2748
Copy link

@Tumelo2748
@MissAngelaKing
@Skosanalindo061

  1. The methods use for Http in RESTful API
  • GET: Retrieve a resource (e.g., fetch a user's data)
  • POST: Create a new @resource (e.g., create a new user account)
  • PUT: Update an existing resource (e.g., update a user's profile)
  • DELETE: Delete a resource (e.g., delete a user account)
  • PATCH: Partially update an existing resource (e.g., update a user's email address)
  • OPTIONS: Return the HTTP methods supported by a resource
  • HEAD: Return metadata about a resource (e.g., headers only)
  • 1xx: Informational responses. These codes indicate that the request has been received and the server is processing it.
  • 2xx: Success responses. These codes indicate that the request was successful and the server has returned the requested data.
  • 3xx: Redirection responses. These codes indicate that the resource has been moved to a new URL or the server wants the client to perform an additional action.
  • 4xx: Client error responses. These codes indicate that the client sent an invalid request or cannot access the resource.
  • 5xx: Server error responses. These codes indicate that the server encountered an error and cannot fulfill the request.
  1. Response Functions:
  • res.send(): Send a response with a string or buffer body
  • res.json(): Send a response with a JSON body
  • res.render(): Render a template and send the rendered HTML as the response
  • OK: 200. Use when the request was successful and the server has returned the requested data.
  • Bad Request: 400. Use when the client sent an invalid request or the server cannot process it.
  • Unauthorized: 401. Use when the client is not authenticated or does not have valid credentials.
  • Forbidden: 403. Use when the client is authenticated but does not have permission to access the resource.
  • Not Found: 404. Use when the requested resource does not exist on the server.
  • Internal Server Error: 500. Use when the server encountered an unexpected error and cannot fulfill the request

@NtokozoMitchell
Copy link

@Pamela Gwala
@Yenkosii

1.GET: Retrieve data from the server.
Use: Fetch resources.
Example: GET /users (list of users), GET /users/1 (specific user).

b)POST: Submit data to create a new resource.
Use: Add new resources.
Example: POST /users (create a new user).

c)PUT: Update an existing resource completely.
Use: Replace a resource.
Example: PUT /users/1 (update user data).

d)PATCH: Update an existing resource partially.
Use: Modify part of a resource.
Example: PATCH /users/1 (update specific fields).
e)DELETE: Remove a resource.
Use: Delete resources.
Example: DELETE /users/1 (delete a user).

f)HEAD: Retrieve headers for a resource.
Use: Get metadata.
Example: HEAD /users/1 (headers for a user).

g)OPTIONS: Retrieve supported HTTP methods for a resource.
Use: Discover allowed operations.
Example: OPTIONS /users (methods supported).

h)TRACE: Echo the received request for debugging.
Use: Debug requests.
Example: TRACE /users/1 (echo request).

i)CONNECT: Establish a tunnel to the server.
Use: Create a network connection.
Exam
Example: CONNECT /users (tunnel connection).

2.1xx: Informational
100 Continue: The initial part of a request has been received, and the client should continue with the request.
101 Switching Protocols: The server is switching protocols as requested by the client (e.g., from HTTP/1.1 to WebSocket).
b)2xx: Success
200 OK: The request has succeeded.
201 Created: The request has been fulfilled, and a new resource has been created.
202 Accepted: The request has been accepted for processing, but the processing is not complete.
204 No Content: The request has been successfully processed, but there is no content to return.
c)3xx: Redirection
301 Moved Permanently: The resource has been permanently moved to a new URL.
302 Found: The resource is temporarily available at a different URL.
304 Not Modified: The resource has not been modified since the last request, so the client can use the cached version.
d)4xx: Client Errors
400 Bad Request: The server cannot or will not process the request due to client error (e.g., malformed request syntax).
401 Unauthorized: Authentication is required, and the request has not been applied because it lacks valid credentials.
403 Forbidden: The server understands the request but refuses to authorize it.
404 Not Found: The requested resource could not be found.
405 Method Not Allowed: The method specified in the request is not allowed for the resource.
409 Conflict: The request could not be completed due to a conflict with the current state of the resource.
e)5xx: Server Errors
500 Internal Server Error: The server encountered an unexpected condition that prevented it from fulfilling the request.
501 Not Implemented: The server does not support the functionality required to fulfill the request.
502 Bad Gateway: The server, while acting as a gateway or proxy, received an invalid response from an upstream server.
503 Service Unavailable: The server is currently unable to handle the request due to temporary overload or maintenance.
504 Gateway Timeout: The server, while acting as a gateway or proxy, did not receive a timely response from an upstream server.

3.a)res.send():
Purpose: Sends a JSON response.
Use Case: When you want to send a JSON object. It sets the Content-Type header to application/json automatically

b)res.json():
Purpose: Sends a JSON response.
Use Case: When you want to send a JSON object. It sets the Content-Type header to application/json automatically.
c)res.render():
Purpose: Renders a view template and sends the HTML response.
Use Case: When you want to render a view (HTML page) using a templating engine (e.g., Pug, EJS).

4.a)Status Code OK
Code: 200
Description: The request has succeeded. This is the standard response for successful HTTP requests.

b)Status Code Unauthorized
Code: 401
Description: The request requires user authentication. The client must authenticate itself to get the requested response.
Status Code Forbidden
c)Code: 403
Description: The server understands the request but refuses to authorize it. This is typically due to lack of permissions.
d)Status Code Not Found
Code: 404
Description: The server cannot find the requested resource. This status code is returned when the server cannot find what was requested
unexpected conditions.
e)Status Code Internal Server Error
Code: 500
Description: The server has encountered a situation it doesn't know how to handle. This is a generic error message for unexpected conditions.
f)status code 400 Bad Request indicates that the server cannot or will not process the request due to something perceived as a client error.

@PhamelaMhlaba
Copy link

Partners (Phamela and Sharon)

  1. In RESTful APIs, HTTP methods are used to perform different operations on resources. Here are
    the primary methods and their typical uses:
  • GET is used to retrieve data from s server and is used when we want to fetch a list of users or
    getting details for a specific user.
  • POST is used to send data to a server to create a new resource and is used when submitting
    forms or creating a new user
  • PUT updates an existing resource and used to update the profile of the user
  • PATCH updates an existing resource partially and is used to update the email address of the user
  • DELETE removes a resource from the server and is used to delete the user account
  • OPTIONS describe available communications options for a resource. Check which HTTP methods
    are supported for a resource (e.g, findin out if you can use GET, POST, etc, on a user resource).
  1. 1xx (Informational):

Purpose: Request received, continuing process.
Example: 100 Continue - Request headers received, proceed with request body.

2xx (Success):

Purpose: Request successfully received, understood, and accepted.
Example: 200 OK - Request succeeded.

3xx (Redirection):

Purpose: Further action needed to complete the request.
Example: 301 Moved Permanently - Resource permanently moved to a new URL.

4xx (Client Error):

Purpose: Client-side error, bad request.
Example: 404 Not Found - Resource not found.

5xx (Server Error):

Purpose: Server-side error, failed to fulfill a valid request.
Example: 500 Internal Server Error - Server encountered an unexpected error.

  1. Differences between the following responses.
    res.send():

Purpose: Send a response of any type (HTML, text, JSON, etc.).
Use Case: General-purpose response sending.
res.json():

Purpose: Send a JSON response.
Use Case: Specifically for sending JSON data.
res.render():

Purpose: Render a view template.
Use Case: Generate and send HTML using a template engine.

  1. 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