0.14.1 • Published 3 days ago

@pyriter/unrest v0.14.1

Weekly downloads
-
License
GPL
Repository
github
Last release
3 days ago

Unrest

Patreon

Description

Request routing for AWS Lambda running Nodejs, written in Typescript

Motivation: Existing routing libraries are inefficient. This library uses a trie data structure with local caching to improve lookup and response time. (More latency data to come)

Install

npm install @pyriter/unrest

Features

  1. Define routes
  2. Define controllers
  3. Type the request body

One Time Setup

Set the "noStrictGenericChecks" to true in your tsconfig to avoid typescript errors

{
  "compilerOptions": {
    ...
    "noStrictGenericChecks": true
    ...
  }
}

Usage

Simple HTTP GET example

import { StatusType, Unrest } from "@pyriter/unrest";
import { APIGatewayProxyEvent, APIGatewayProxyStructuredResultV2 } from "aws-lambda";

class ApiServiceHandler {
  private readonly unrest: Unrest;

  constructor() {
    this.unrest = Unrest.builder()
      .withRoute({
        method: MethodType.GET,
        path: "/api/v1/ping",
        handler: async (): Promise<Response> => {
          return Response.builder()
            .withStatusCode(StatusType.OK)
            .withBody({
              message: "success"
            }).build();
        }
      })
      .build();
  }

  async handle(event: APIGatewayProxyEvent):
    Promise<APIGatewayProxyStructuredResultV2> {
    return await this.unrest.execute(event);
  }
}

Additional Route Examples

You can use openApi style URL params to define key value pairs like this {keyName}.

const unrest = Unrest.builder()
  .withRoute({
    method: MethodType.GET,
    path: '/api/v1/ping',
    handler: pingController.getPing,
    thisReference: pingController
  })
  .withRoute({
    method: MethodType.POST,
    path: '/api/v1/account',
    handler: accountController.postAccount,
    thisReference: accountController
  })
  .withRoute({
    method: MethodType.PUT,
    path: '/api/v1/account/{accountId}',
    handler: accountController.putAccount,
    thisReference: accountController
  })
  .withRoute({
    method: MethodType.DELETE,
    path: '/api/v1/account/{accountId}',
    handler: accountController.deleteAccount,
    thisReference: accountController
  })
  .withRoute({
    method: MethodType.GET,
    path: '/api/v1/user/{userId}/order/{orderId}',
    handler: orderController.getOrderFromUser,
    thisReference: orderController
  })
  .build();
0.14.1

3 days ago

0.14.0

16 days ago

0.12.0

24 days ago

0.13.0

24 days ago

0.11.0

25 days ago

0.10.0

1 month ago

0.9.0

2 months ago

0.8.0

2 months ago

0.7.0

2 months ago

0.6.7

3 months ago

0.6.6

3 months ago

0.6.9

3 months ago

0.6.8

3 months ago

0.6.10

3 months ago

0.6.11

3 months ago

0.6.5

3 months ago

0.6.3

3 months ago

0.6.2

3 months ago

0.6.4

3 months ago

0.6.1

3 months ago

0.6.0

3 months ago

0.5.0

5 months ago

0.1.0

5 months ago

0.3.0

5 months ago

0.2.0

5 months ago

0.0.10

5 months ago

0.0.9

5 months ago

0.0.8

5 months ago

0.0.5

5 months ago

0.0.7

5 months ago

0.0.6

5 months ago

0.0.4

5 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago