HTTP & APIs
Endpoint
An endpoint is a specific URL path + HTTP method pair that routes a request to a dedicated handler function on the server.
Diagram
Server's Routing Table: ┌──────────────────────────────────────────┐ │ GET /api/v1/users → listUsers() │ │ POST /api/v1/users → createUser() │ │ DEL /api/v1/users/:id → deleteUser() │ └──────────────────────────────────────────┘ Incoming: POST /api/v1/users → matches row 2
In Depth
An endpoint is the entry point or address exposed by a web server, formed by combining an HTTP verb (method) with a URL path (e.g. GET /api/v1/users). It represents the physical destination where a client sends a request.
Code Example
Express.js route registration
// Registering an endpoint
app.get('/api/v1/users/:id', async (req, res) => {
const userId = req.params.id; // Path param
const user = await database.find(userId);
if (!user) return res.status(404).json({ error: 'Not found' });
return res.json(user);
});