All academies

Simulator

HTTP Server Simulator

Define routes on a virtual Node.js server, fire requests from a virtual client, and watch every request travel the wire, get matched to a route, and come back with a semantically correct status code.

Server definition

Edit the route table — the code updates live

200
200
201
204
server.js
const http = require('http');

const server = http.createServer((req, res) => {
  if (req.method === 'GET' && req.url === '/users') {
    res.writeHead(200, { 'Content-Type': 'application/json' });
    return res.end('[{"id":1,"name":"Ada"},{"id":2,"name":"Linus"}]');
  }

  if (req.method === 'GET' && req.url === '/users/1') {
    res.writeHead(200, { 'Content-Type': 'application/json' });
    return res.end('{"id":1,"name":"Ada"}');
  }

  if (req.method === 'POST' && req.url === '/users') {
    res.writeHead(201, { 'Content-Type': 'application/json' });
    return res.end('{"id":3,"name":"Grace"}');
  }

  if (req.method === 'DELETE' && req.url === '/users/1') {
    res.writeHead(204);
    return res.end();
  }

  res.writeHead(404, { 'Content-Type': 'application/json' });
  res.end('{"error":"Not Found"}');
});

server.listen(3000, () => {
  console.log('Listening on http://localhost:3000');
});

Client

Compose a request and send it to the server

localhost:3000

The response will appear here.

Request lifecycle

Client
Server

Send a request to see it travel the wire.

Request log

No requests yet.