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
@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