{"id":13528378,"url":"https://github.com/balmbees/corgi","last_synced_at":"2025-10-27T20:30:40.752Z","repository":{"id":44218309,"uuid":"93131984","full_name":"balmbees/corgi","owner":"balmbees","description":"AWS Lambda / API Gateway native, fast and simple web framework","archived":false,"fork":false,"pushed_at":"2023-01-11T11:50:26.000Z","size":549,"stargazers_count":52,"open_issues_count":23,"forks_count":3,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-02-08T14:34:00.175Z","etag":null,"topics":["api-gateway","aws-lambda","corgi","lambda","node","server","serverless","serverless-express","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/balmbees.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-02T05:55:32.000Z","updated_at":"2024-12-27T06:28:50.000Z","dependencies_parsed_at":"2023-02-09T02:45:38.454Z","dependency_job_id":null,"html_url":"https://github.com/balmbees/corgi","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balmbees%2Fcorgi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balmbees%2Fcorgi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balmbees%2Fcorgi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balmbees%2Fcorgi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/balmbees","download_url":"https://codeload.github.com/balmbees/corgi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238551319,"owners_count":19491066,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-gateway","aws-lambda","corgi","lambda","node","server","serverless","serverless-express","typescript"],"created_at":"2024-08-01T06:02:29.041Z","updated_at":"2025-10-27T20:30:35.334Z","avatar_url":"https://github.com/balmbees.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"[![Travis Build Status](https://travis-ci.org/balmbees/corgi.svg?branch=master)](https://travis-ci.org/balmbees/corgi)\n[![npm version](https://badge.fury.io/js/vingle-corgi.svg)](https://badge.fury.io/js/vingle-corgi)\n\n# Corgi\n[Grape](https://github.com/ruby-grape/grape) like lightweight HTTP API Framework for AWS Lambda\n\n## Example\n```typescript\nconst router = new Router([\n  new Namespace('/api/:userId', {\n    params: {\n      userId: Joi.number(),\n    },\n    async before() {\n      this.params.user = await User.findByUserId(this.params.userId);\n      if (!this.params.user) {\n        this.json({\n          error: \"User not exists!\",\n        }, 404);\n        // You can also just throw error - which goes to exceptionHandler\n      }\n    },\n    async exceptionHandler(error) {\n      // Global Exception Handling.\n      if (error.name === 'ValidationError') {\n        const validationError = error as Joi.ValidationError;\n        return this.json(\n          {\n            errors: validationError.details.map(e =\u003e e.message),\n          },\n          422\n        );\n      }\n    },\n    children: [\n      Route.GET('/followers', {}, 'List of users that following me', async function() {\n        return this.json({\n          data: {}\n        })\n      }),\n      new Namespace('/followings', {\n        children: [\n          Route.POST('/', '', {}, async function() {\n            const user = this.params.user as User;\n            return this.json({ userId: user.id });\n          }),\n\n          Route.DELETE('/', '', {}, async function() {\n            const user = this.params.user as User;\n            return this.json({ userId: user.id });\n          }),\n        ]\n      })\n    ]\n  })\n]);\n\n// this goes directly into lambda.\nexport const handler = router.handler();\n```\n\nOr refer src/__test__/e2e/complex_api.ts\n\n\n## How to start\n1. npm install vingle-corgi\n2. exports.handler = new Router([routes]).handler();\n3. deploy lambda\n\n\n## Why do I need an extra Framework for Lambda?\n\nSo simple lambda handler looks like this\n\n```js\nexports.myHandler = function(event, context, callback) {\n   console.log(\"value1 = \" + event.key1);\n   console.log(\"value2 = \" + event.key2);\n   callback(null, \"some success message\");\n}\n```\n\nlet's say you connected API Gateway, (using serverless maybe),\nas Lambda Proxy. and built some Restful API with that.\n\n```js\nexports.myHandler = function(event, context, callback) {\n  if (\n    event.path === '/api/someapi'\n    \u0026\u0026 event.method == 'GET'\n  ) {\n    callback(\n      null, {\n        statusCode: 200,\n        headers: {\n          'Content-Type': 'application/json',\n        },\n        body: JSON.stringify({\n          data: {\n            response: \"XXX\"\n          }\n        })\n      }\n    )\n  } else {\n    callback(\n      null, {\n        statusCode: 404,\n        headers: {\n          'Content-Type': 'application/json',\n        },\n        body: JSON.stringify({\n          error: 'Not Found',\n        })\n      }\n    )\n  }\n}\n```\n\nOk, fairly good, since it's on lambda and APIGateway so everything is managed and scaled....etc.  \nbut also you can clearly see that this is at the tipping point of going unmanageable. \n\nthere are several frameworks that built for this,  \n(such as running express itself on lambda, even though which is what exactly AWS APIGateway is for)  \n[lambda-req](https://www.npmjs.com/package/lambda-req)  \n[aws-serverless-express](https://github.com/awslabs/aws-serverless-express)  \n[serverless-express](https://claudiajs.com/tutorials/serverless-express.html)  \n\nAt Vingle, we did consider about using these kinds of express wrapping.  \nBut those are really inefficient and not reliable for production usage,   \nand, most of all, We really thought we can do better.  \nInspired by [Grape](https://github.com/ruby-grape/grape) a lot, since we really liked it\n\n## Features\n1. Cascade Routing\n2. Route parameter\n    - such as \"users/:userId/followings\"\n3. Parameter Validation\n    - it uses [Joi](https://github.com/hapijs/joi)\n4. Exception Handling\n    - refer [example](src/__test__/e2e/complex_api.ts)\n5. Swagger Document Generation\n    - [Swagger](http://swagger.io/) is API Documentation spec. Corgi support automatic swagger document generation.\n    - refer [example](src/swagger/__test__/index_spec.ts#L148)\n6. View\n    - Named \"Presenter\". basically, you return \"model\" from Route, and \"presenter\" defines how you convert this model into HTTP resource such as JSON\nThe whole thing supports async/await!, written in typescript from scratch also\n\n## Requirements\nFrom v2.0, it only supports lambda nodejs8.10. if you need 6.10 support, either use v1.x or wrap router.handler\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbalmbees%2Fcorgi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbalmbees%2Fcorgi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbalmbees%2Fcorgi/lists"}