Make requests that are representative of HTTP requests to a function.
Get responses that are representative of HTTP responses.
Accepts connect middleware.
Easier to test your server code (using direct function calls).
Faster to test your server code (no HTTP required).
Can be wrapped by any server.
Easy to read logging.
Example
The sans-server package is a tool for building a functional web server that is independent of networking. As a functional library, requests can be made to it and responses provided by it.
const SansServer = require('sans-server');// create a server instanceconst server = SansServer();// add middleware to the serverserver.use(function(req, res, next) { if (req.path === '/') { res.send('OK'); } else { next(); }});// make a request against the serverserver.request({ path: '/' }, function(response) { console.log(response.statusCode); // 200 console.log(response.body);
Routing
Routing is not built into sans-server so you'll want to use some routing middleware.
Documentation
Sans-Server Instance - An instance can be generated with a configuration. Once an instance exists it's easy to specify middleware and to make requests.
Middleware - The server does almost nothing as is. You need middleware to add functionality.
Request Object - This object is passed into every middleware function and has information about the request made.
Response Object - This object is passed into every middleware function and is used to produce the response.