Skip to main content

Reno

Reno is a thin routing library designed to sit on top of Deno’s standard HTTP module.

import { serve } from 'https://deno.land/std@v0.23.0/http/server.ts';

import {
  createRouter,
  AugmentedRequest,
  createRouteMap,
  textResponse,
  jsonResponse,
  streamResponse,
} from 'https://raw.githubusercontent.com/jamesseanwright/reno/v0.5.1/reno/mod.ts';

export const routes = createRouteMap([
  ['/home', () => textResponse('Hello world!')],

  // Supports RegExp routes for further granularity
  [/^\/api\/swanson\/?([0-9]?)$/, async (req: AugmentedRequest) => {
    const [quotesCount = '1'] = req.routeParams;

    const res = await fetch(
      `https://ron-swanson-quotes.herokuapp.com/v2/quotes/${quotesCount}`,
    );

    return jsonResponse(await res.json());
  }],

  // Supports Reader for streaming responses in chunks
  ['/streamed-response', () => streamResponse(
    new ReactReader(<App />),
  )],
]);

const router = createRouter(routes);

(async () => {
  console.log('Listening for requests...');

  for await (const req of serve(':8001')) {
    req.respond(await router(req));
  }
})();

TODO: ADD UNIT TESTING EXAMPLE!

Local Development

Once you’ve cloned the repository, you’ll need to ensure you’re running the version of Deno against which this project is developed; this is stored in .deno-version. To install the correct version, run:

$ curl -fsSL https://deno.land/x/install/install.sh | sh -s $(cat .deno-version)

You should also run ./tools/install-types.sh to install the TypeScript definitions for Deno and any other third-party dependencies.

Then you can run:

  • deno example/index.ts - starts the example server
  • deno test - runs the unit tests

Functionality Checklist

  • Path routing
  • Async-compatible route handlers
  • Error handling
  • Route params
  • Query params
  • Response helpers
  • JSON
  • Custom headers
  • Request bodies
  • Cookies
  • Streaming responses with Reader
  • Streaming request bodies

Is middleware support planned?

Not directly, but Reno will eventually export a pipe function to combine multiple route handlers.