One of the most commonly used API endpoints is the GET all route, which returns the entire data list — for example, all users, all products, or all posts.
const express = require('express');
const app = express();
let users = [
{ id: 1, name: 'Aung Aung' },
{ id: 2, name: 'Mya Mya' }
];
app.get('/api/users', (req, res) => {
res.json({
count: users.length,
data: users
});
});
app.listen(3000, () => console.log('API running on port 3000'));app.get('/api/users') is called by the client, it returns the users array as JSON. Including count makes it easy for the frontend to know the total number of items.
GET /api/users { "count": 2, "data": [ { "id": 1, "name": "Aung Aung" }, { "id": 2, "name": "Mya Mya" } ] }Info
You could return just an array as the API response too. But using an object structure like { count, data } makes it easy to add things like pagination, message, or status later on.