All Projects → balmbees → Corgi

balmbees / Corgi

Licence: mit
AWS Lambda / API Gateway native, fast and simple web framework

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Corgi

Serverless Sharp
Serverless image optimizer for S3, Lambda, and Cloudfront
Stars: ✭ 102 (+131.82%)
Mutual labels:  api-gateway, serverless, aws-lambda, lambda
Zappa
Serverless Python
Stars: ✭ 11,859 (+26852.27%)
Mutual labels:  api-gateway, serverless, aws-lambda, lambda
Up
Up focuses on deploying "vanilla" HTTP servers so there's nothing new to learn, just develop with your favorite existing frameworks such as Express, Koa, Django, Golang net/http or others.
Stars: ✭ 8,439 (+19079.55%)
Mutual labels:  api-gateway, serverless, aws-lambda, lambda
Serverless Es Logs
A Serverless plugin to transport logs to ElasticSearch
Stars: ✭ 51 (+15.91%)
Mutual labels:  api-gateway, serverless, aws-lambda, lambda
Grant
OAuth Proxy
Stars: ✭ 3,509 (+7875%)
Mutual labels:  serverless, aws-lambda, lambda, server
Serverless Sinatra Sample
Demo code for running Ruby Sinatra on AWS Lambda
Stars: ✭ 195 (+343.18%)
Mutual labels:  api-gateway, serverless, aws-lambda, lambda
Serverless Next.js
⚡ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
Stars: ✭ 2,977 (+6665.91%)
Mutual labels:  api-gateway, serverless, aws-lambda, lambda
Serverless Express
Run Node.js web applications and APIs using existing application frameworks on AWS #serverless technologies such as Lambda, API Gateway, Lambda@Edge, and ALB.
Stars: ✭ 4,265 (+9593.18%)
Mutual labels:  api-gateway, serverless, aws-lambda, lambda
Aegis
Serverless Golang deploy tool and framework for AWS Lambda
Stars: ✭ 277 (+529.55%)
Mutual labels:  api-gateway, serverless, aws-lambda, lambda
Zappa
Serverless Python
Stars: ✭ 224 (+409.09%)
Mutual labels:  api-gateway, serverless, aws-lambda, lambda
Vandium Node
AWS Lambda framework for building functions using Node.js for API Gateway, IoT applications, and other AWS events.
Stars: ✭ 377 (+756.82%)
Mutual labels:  api-gateway, serverless, aws-lambda, lambda
Mangum
AWS Lambda & API Gateway support for ASGI
Stars: ✭ 475 (+979.55%)
Mutual labels:  api-gateway, serverless, aws-lambda, lambda
Archive aws Lambda Go
A fast and clean way to execute Go on AWS Lambda.
Stars: ✭ 710 (+1513.64%)
Mutual labels:  serverless, aws-lambda, lambda
Aws Mobile React Sample
A React Starter App that displays how web developers can integrate their front end with AWS on the backend. The App interacts with AWS Cognito, API Gateway, Lambda and DynamoDB on the backend.
Stars: ✭ 650 (+1377.27%)
Mutual labels:  api-gateway, serverless, lambda
Lambda Packages
Various popular python libraries, pre-compiled to be compatible with AWS Lambda
Stars: ✭ 713 (+1520.45%)
Mutual labels:  serverless, aws-lambda, lambda
Terraform Nextjs Plugin
A plugin to generate terraform configuration for Nextjs 8 and 9
Stars: ✭ 41 (-6.82%)
Mutual labels:  api-gateway, serverless, lambda
Aws Sam Cli
CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
Stars: ✭ 5,817 (+13120.45%)
Mutual labels:  api-gateway, serverless, lambda
Serverless Domain Manager
Serverless plugin for managing custom domains with API Gateways.
Stars: ✭ 783 (+1679.55%)
Mutual labels:  api-gateway, serverless, lambda
Archive aws Lambda Go Shim
Author your AWS Lambda functions in Go, effectively.
Stars: ✭ 799 (+1715.91%)
Mutual labels:  serverless, aws-lambda, lambda
Lambdalogs
A CLI tool to trace AWS Lambda calls over multiple CloudWatch log groups.
Stars: ✭ 18 (-59.09%)
Mutual labels:  serverless, aws-lambda, lambda

Travis Build Status npm version

Corgi

Grape like lightweight HTTP API Framework for AWS Lambda

Example

const router = new Router([
  new Namespace('/api/:userId', {
    params: {
      userId: Joi.number(),
    },
    async before() {
      this.params.user = await User.findByUserId(this.params.userId);
      if (!this.params.user) {
        this.json({
          error: "User not exists!",
        }, 404);
        // You can also just throw error - which goes to exceptionHandler
      }
    },
    async exceptionHandler(error) {
      // Global Exception Handling.
      if (error.name === 'ValidationError') {
        const validationError = error as Joi.ValidationError;
        return this.json(
          {
            errors: validationError.details.map(e => e.message),
          },
          422
        );
      }
    },
    children: [
      Route.GET('/followers', {}, 'List of users that following me', async function() {
        return this.json({
          data: {}
        })
      }),
      new Namespace('/followings', {
        children: [
          Route.POST('/', '', {}, async function() {
            const user = this.params.user as User;
            return this.json({ userId: user.id });
          }),

          Route.DELETE('/', '', {}, async function() {
            const user = this.params.user as User;
            return this.json({ userId: user.id });
          }),
        ]
      })
    ]
  })
]);

// this goes directly into lambda.
export const handler = router.handler();

Or refer src/test/e2e/complex_api.ts

How to start

  1. npm install vingle-corgi
  2. exports.handler = new Router([routes]).handler();
  3. deploy lambda

Why do I need an extra Framework for Lambda?

So simple lambda handler looks like this

exports.myHandler = function(event, context, callback) {
   console.log("value1 = " + event.key1);
   console.log("value2 = " + event.key2);
   callback(null, "some success message");
}

let's say you connected API Gateway, (using serverless maybe), as Lambda Proxy. and built some Restful API with that.

exports.myHandler = function(event, context, callback) {
  if (
    event.path === '/api/someapi'
    && event.method == 'GET'
  ) {
    callback(
      null, {
        statusCode: 200,
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          data: {
            response: "XXX"
          }
        })
      }
    )
  } else {
    callback(
      null, {
        statusCode: 404,
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          error: 'Not Found',
        })
      }
    )
  }
}

Ok, fairly good, since it's on lambda and APIGateway so everything is managed and scaled....etc.
but also you can clearly see that this is at the tipping point of going unmanageable.

there are several frameworks that built for this,
(such as running express itself on lambda, even though which is what exactly AWS APIGateway is for)
lambda-req
aws-serverless-express
serverless-express

At Vingle, we did consider about using these kinds of express wrapping.
But those are really inefficient and not reliable for production usage,
and, most of all, We really thought we can do better.
Inspired by Grape a lot, since we really liked it

Features

  1. Cascade Routing
  2. Route parameter
    • such as "users/:userId/followings"
  3. Parameter Validation
  4. Exception Handling
  5. Swagger Document Generation
    • Swagger is API Documentation spec. Corgi support automatic swagger document generation.
    • refer example
  6. View
    • Named "Presenter". basically, you return "model" from Route, and "presenter" defines how you convert this model into HTTP resource such as JSON The whole thing supports async/await!, written in typescript from scratch also

Requirements

From v2.0, it only supports lambda nodejs8.10. if you need 6.10 support, either use v1.x or wrap router.handler

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].