0.2.2 • Published 1 year ago

@gthole/open-api-router v0.2.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

OpenAPI Router

Warning: This is in early development and not recommended for production use yet.

An opinionated framework for routing HTTP requests to controller logic via an OpenAPI spec.

This library is intended for use in place of Express when running in an AWS Lambda-based Serverless environment, where a single Lambda responds to multiple paths/endpoints.

The rationale is that using Express in Lambda converts an object request into a socket request and then reads the response off the socket while serializing and deserializing additonal context in headers. It's much easier to just handle the request itself.

Features

  • Document-driven functionality.
  • Middleware via SecurityDefinitions.
  • JSON-schema validation with AJV.
  • Response compression.
  • Convenience methods for HTTP responses.

Examples

API Gateway

import { Request, Response } from 'open-api-router';

class DocumentsController {
    getById(req: Request, resp: Response) {
        const doc = await db.documents.findOne(req.params.id);
        if (!doc) {
            return resp.notFound();
        }
        resp.ok({data: doc});
    }
}

export = new DocumentsController();
import { ApiGatewayOpenApiRouter } from 'open-api-router';
import documents from './controllers/documents`;

// Create the Swagger Router with API Gateway type bindings
const router = new ApiGatewayOpenApiRouter({
    location: '../swagger.yml',
    controllers: { documents },
});

export handler = async (ev) => router.handle(ev);
0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago