Route using open API specification

Usage no npm install needed!

<script type="module">
  import tuckerconnellyMinimalRouter from 'https://cdn.skypack.dev/@tuckerconnelly/minimal-router';


Early Version


Minimal Node.js router.


npm i @tuckerconnelly/minimal-router

Then where you define your HTTP server:

const http = require('http');

const minimalRouter = require('@tuckerconnelly/minimal-router');

  minimalRouter(`${__dirname}/routes`)((req, res) => {
    res.statusCode = 404;
    res.end('Not Found');

Then in routes/test-endpoint.js add:

// Optional, defaults to ['post']
exports.methods = ['get']
// Required
exports.default = (req, res) => res.end('OK');

Then you can make calls to that route function:

> curl localhost:3000/test-endpoint


Any file in the passed folder with those exports will get picked up and routed to.

Whatever you do, work at it with all your heart, as working for the Lord, not for human masters, since you know that you will receive an inheritance from the Lord as a reward.

Colossians 3:23