Skip to content

Instantly share code, notes, and snippets.

@halitbatur
Created December 13, 2023 12:12
Show Gist options
  • Select an option

  • Save halitbatur/d50bd5c96d8d5b84fa3b179f71194131 to your computer and use it in GitHub Desktop.

Select an option

Save halitbatur/d50bd5c96d8d5b84fa3b179f71194131 to your computer and use it in GitHub Desktop.
Rest discussion questions

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

Copy link
Copy Markdown

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