You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Defines a set of constraints to be used for creating web services.
Use HTTP methods like GET, POST, PUT, and DELETE to perform operations on resources identified by URIs.
Allow accessing web services in a simple and flexible way without having any processing.
Resource-based and stateless
Resources are defined using nouns. e.g., /users
Ideal for web servers
Benefits
Standardization
Statelessness
Flexibility (of resource or methods)
Interoperability
GET /api/users/123
A simple REST API in [[Express]]:
letusers=[{id: 1,name: "John Doe",email: "[email protected]"},{id: 2,name: "Jane Smith",email: "[email protected]"},];// GET /users - Retrieve all usersapp.get("/users",(req,res)=>{res.json(users);});// GET /users/:id - Retrieve a specific userapp.get("/users/:id",(req,res)=>{constuser=users.find((u)=>u.id===parseInt(req.params.id));if(!user){returnres.status(404).json({error: "User not found"});}res.json(user);});// POST /users - Create a new userapp.post("/users",(req,res)=>{const{ name, email }=req.body;constnewUser={id: users.length+1, name, email };users.push(newUser);res.status(201).json(newUser);});// PUT /users/:id - Update an existing userapp.put("/users/:id",(req,res)=>{const{ name, email }=req.body;constuser=users.find((u)=>u.id===parseInt(req.params.id));if(!user){returnres.status(404).json({error: "User not found"});}user.name=name;user.email=email;res.json(user);});// DELETE /users/:id - Delete a userapp.delete("/users/:id",(req,res)=>{constindex=users.findIndex((u)=>u.id===parseInt(req.params.id));if(index===-1){returnres.status(404).json({error: "User not found"});}constdeletedUser=users.splice(index,1)[0];res.json(deletedUser);});
[[GraphQL]]
A query language for APIs and a runtime for fulfilling those queries with existing data.
Protocol-agnostic
Reduce network load by giving clients the power to ask for exactly what they need.
query {
user(id: "123") {
name
email
}
}
SOAP
Simple Object Access Protocol
A protocol specification for exchanging structured information in the implementation of web services in computer networks.
Use XML-based messages that follow a specific format.
Ideal for enterprise-level applications that require high security and transactional reliability.
Suitable for private APIs, especially in industries like finance and healthcare, where data integrity and security are important.
The OpenAPI Specification (OAS) is a community-driven open specification that provides a standard, language-agnostic interface to describe RESTful APIs.
It describes RESTful APIs in a machine-readable format, enabling a variety of tooling and automation around API development and consumption.
It is maintained and developed by the OpenAPI Initiative under the Linux Foundation.
Formerly known as the Swagger Specification.
Key points:
It defines a standard way to describe HTTP APIs, allowing both humans and machines to understand the capabilities of a service without additional documentation or inspection of network traffic.
It supports use cases such as interactive documentation, code generation for clients and servers, and automation of test cases facilitating both design-first and code-first API development approaches.
It is represented in either YAML or JSON formats and can be produced statically or generated dynamically from an application.