Lesson 8 of 8
Building a Simple API
You can build APIs using any backend language. The concept is the same: listen for HTTP requests, process them, and return JSON. Here is a simple example using Node.js and Express.
APIS
const express = require("express");
const app = express();
app.use(express.json());
// GET all users
app.get("/users", (req, res) => {
res.json([{ id: 1, name: "Ali" }]);
});
// POST new user
app.post("/users", (req, res) => {
const newUser = req.body;
res.status(201).json(newUser);
});
app.listen(3000);