Skip to content

Instantly share code, notes, and snippets.

@Kishimoto96
Created April 13, 2023 16:07
Show Gist options
  • Save Kishimoto96/887437cb456f355f4211b1414a63235b to your computer and use it in GitHub Desktop.
Save Kishimoto96/887437cb456f355f4211b1414a63235b to your computer and use it in GitHub Desktop.

RESTful API Discussion Questions

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

1- Rasam Rabiee @cyberRasam
2- Baraah Masri
3- Talal Bakkour
4- Nour Eddin Hamouda

Answers :

1- A traditional API, also known as a SOAP API, relies on XML as a format for exchanging data and is typically accessed using the Simple Object Access Protocol (SOAP). On the other hand, a RESTful API is a more flexible approach to web services, relying on HTTP and the principles of Representational State Transfer (REST), It uses a lightweight data format, such as JSON or XML, for exchanging data and supports a wider range of HTTP methods (GET, POST, PUT, DELETE, etc.). While REST API and RESTful API are often used interchangeably, they have distinct differences. REST API is an API that follows the principles of the REST architecture, while RESTful API is an API that follows the principles of the REST architecture and meets specific requirements1.

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

3- HTTP status codes are three-digit numbers that indicate the status of a web server’s response to a client’s request. The first digit of the status code defines the class of response. The last two digits do not have any categorization role. There are five classes of HTTP status codes:

1xx (Informational): These status codes indicate a provisional response. The client should continue with its request.
2xx (Successful): These status codes indicate that the server successfully processed the request and returned the expected response.
3xx (Redirection): These status codes indicate that further action needs to be taken by the user agent in order to fulfill the request.
4xx (Client Error): These status codes indicate that the client has made an error in its request.
5xx (Server Error): These status codes indicate that the server has encountered an error while processing the request.

4- res.send(): This method sends a simple response to the client. It can send a string, buffer, HTML, or JSON data. If you pass a string, it will be sent as plain text. If you pass JSON data, it will be sent as an application/JSON content type. res.send('Hello World!');

res.json(): This method sends a JSON response to the client. It automatically sets the content type to application/JSON. res.json({ message: 'Hello World!' });

res.render(): This method is used to render a view and send the HTML to the client. It is typically used with a templating engine like EJS, Handlebars, or Pug.
res.render('index', { title: 'Homepage' });

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

@mahmoudsha
Copy link

@Mahmoud-Alshahin @Berra-Mahmut @Harith-Riyadh @Guled-Khadar-Abdi

1- * APIs: uses XML to communicate between different systems, and it uses HTTP POST or GET requests to exchange information between systems.

RESTful APIs: uses a common set of HTTP verbs like GET, POST, PUT, and DELETE to perform operations on resources, and it also uses HTTP requests to perform CRUD (Create, Read, Update, and Delete) operations on resources identified by URIs (Uniform Resource Identifiers)
the main difference between RESTful APIs and traditional APIs is their architectural style and the way they handle data. Traditional APIs use a Remote Procedure Call (RPC) style, while RESTful APIs use a more lightweight and flexible architecture based on the principles of Representational State Transfer (REST). RESTful APIs are generally considered to be more flexible, scalable, and easier to work with than traditional APIs, although they may not always be the best choice for every use case.

2- The primary or most-commonly-used HTTP verbs (or methods, as they are properly called) are POST, GET, PUT, PATCH, and DELETE.
POST for Create ,
GET for read,
Put for update/replace
PATCH for update /modify
DELETE for delete

3-Informational responses(100 – 199)
Successful responses (200 – 299)
Redirection messages (300 – 399)infor
Client error responses (400 – 499)
Server error responses(500 – 599)

4- res.send() to send information to client
res.json() to have json
res.render() to render on client side

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

@jimaa-maya
Copy link

Ozlem Keles, Motaz Ali, Nezir Aydin, Tareq Harh, Jimaa Maya

1- A traditional API, also known as a SOAP (Simple Object Access Protocol) API, relies on XML (eXtensible Markup Language) to structure data and uses HTTP (Hypertext Transfer Protocol) for communication. It usually requires a lot of boilerplate code and is more rigid in terms of what it can do.

On the other hand, a RESTful API (Representational State Transfer) is more flexible and lightweight. It uses HTTP methods (GET, POST, PUT, DELETE) to manipulate data and can return data in various formats, such as JSON (JavaScript Object Notation), XML, or even HTML. RESTful APIs rely on a resource-based architecture, where each resource (such as a customer or an order) is identified by a unique URL, and its state is represented by the HTTP methods and responses.
Stateless Design: RESTful APIs are stateless, meaning that each request from a client to a server must contain all the necessary information to understand and process the request. The server does not store any client context between requests, which allows for scalability and simplicity in the API design.

2- POST = Post is to create new subordinate resources,
GET: get is to retrieve resource representation/information only.
PUT: to update an existing resource (if the resource does not exist, then API may decide to create a new resource or not).
PATCH: to make a partial update.
DELETE: delete a resource.

3-Informational responses (100 – 199)
Successful responses (200 – 299)
Redirection messages (300 – 399)
Client error responses (400 – 499)
Server error responses (500 – 599).

4-res.render() it's used for rendering a HTML or EJS templates.
res.send() is a general-purpose function that can send responses of different types.
res.json() is specifically used to send JSON responses.

5- 200 OK
400 bad requests
401 Code Unauthorized
403 Code Forbidden
404 Code Not Found
500 Code Internal Server Error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment