import http from 'node:http'; const items = Array.from({length: 30}, (_,i) => ({ id: i+1, name: `item-${i+1}` })); http.createServer((req,res) => { const url = new URL(req.url, 'http://localhost'); if (req.method !== 'GET' || url.pathname !== '/api/items') { res.writeHead(404).end(); return; } const page = Math.max(1, Number(url.searchParams.get('page') || 1)); const size = Math.min(20, Math.max(1, Number(url.searchParams.get('size') || 10))); const data = items.slice((page-1)*size, page*size); res.writeHead(200, {'content-type':'application/json'}).end(JSON.stringify({ data, page, size, total:items.length })); }).listen(3000, '127.0.0.1');