{"id":18527245,"url":"https://github.com/davidecavaliere/serverless-api-decorators","last_synced_at":"2025-04-09T12:32:19.203Z","repository":{"id":57363375,"uuid":"92597321","full_name":"davidecavaliere/serverless-api-decorators","owner":"davidecavaliere","description":"Typescript decorators to simplify aws lambda functions development with serverless","archived":false,"fork":false,"pushed_at":"2018-08-19T10:58:36.000Z","size":118,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-24T05:51:57.910Z","etag":null,"topics":["aws","aws-lambda","lambda","serverless","typescript"],"latest_commit_sha":null,"homepage":null,"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/davidecavaliere.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-27T12:27:14.000Z","updated_at":"2023-05-15T10:19:34.000Z","dependencies_parsed_at":"2022-09-15T21:23:25.205Z","dependency_job_id":null,"html_url":"https://github.com/davidecavaliere/serverless-api-decorators","commit_stats":null,"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidecavaliere%2Fserverless-api-decorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidecavaliere%2Fserverless-api-decorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidecavaliere%2Fserverless-api-decorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidecavaliere%2Fserverless-api-decorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidecavaliere","download_url":"https://codeload.github.com/davidecavaliere/serverless-api-decorators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247704568,"owners_count":20982298,"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":["aws","aws-lambda","lambda","serverless","typescript"],"created_at":"2024-11-06T17:54:35.857Z","updated_at":"2025-04-09T12:32:18.240Z","avatar_url":"https://github.com/davidecavaliere.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @microgamma/serverless-apigator\n[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com)\n[![Build Status](https://travis-ci.org/davidecavaliere/serverless-api-decorators.svg?branch=master)](https://travis-ci.org/davidecavaliere/serverless-api-decorators)\n[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n\nThis project is mean to simplify and make more elegant aws lambda development in typescript and automatically handle the serverless configuration file.\n\nThis is still under heavy development.  \n\nFeatures:\n  - define your service as a class annotating it to provide configuration\n  - define lambdas as methods of a class and annotate them to provide configuration\n  - lambdas are automatically wrapped into a promise\n  - path and query parameters are automatically injected into the lambda\n  - support for parameters validation\n  - no need to change serverless.yml\n\nAt a glance:\n```typescript\n@Endpoint(\n  // define configuration here\n)\nexport class MyService {\n\n  @Lambda(\n    // define configuration\n  )\n  public sayHello(event) {\n    return { message : 'Hello there'}\n  }\n}\n```\n\nLook into the example folder for a working example\n\n# How to use\n\n#### Create a serverless project\n\n``sls create -t aws-nodejs``\n\n- specify your service name and comment out `functions` section\n\n### TBD. instruction on how to set up for ts lambdas\n\n#### Install sls-api-decorators\n\n```npm i -S sls-api-decorators```\n\nEdit you plugins section and add typescript output folder.\n\n```yaml\nplugins:\n  # this will dynamically set the functions in serverless.yaml\n  - sls-api-decorators\n\ncustom:\n  # this will be your ts output folder\n  artifactsFolder: lib\n\n```\n\ncreate `api/user/user.service.ts`\n\nThe following will define a service with base path users that will expose two endpoints:\n- users/\n- users/error\n\nThe latter being to demostrate error throwing.\n\n```typescript\n// user.service.ts\nimport {Service, Endpoint} from \"sls-api-decorators\";\n\n\n@Endpoint({\n  // name of the service (not in the serverless meaning of service)\n  // will be used in the future for di purpose\n  name: 'userService',\n  // this will rapresent the base path for this service\n  // i.e.: http://localhost:8000/users\n  path: 'users',\n  // Allow xOrigin request [TBD]\n  xOrigin: true\n})\nclass UserService {\n  constructor() { }\n\n  @Lambda({\n    // name to reference this method in the serverless ecosystem\n    // i.e.: to be used with invoke command\n    name: 'hello',\n    // sub-path for this endpoint\n    // i.e.: http://localhost:8000/users/\n    path: '/',\n    // method to which this function should listen\n    // i.e.: 'get' or ['get', 'post'] [TBD]\n    method: 'get',\n    // this is just required from serverless-webpack plugin\n    integration: 'lambda'\n  })\n  public welcome(event) {\n    debug('Running welcome');\n\n    return { message: 'Go Serverless Webpack (Typescript) v1.0! Your function executed successfully!', event };\n\n  }\n\n  // demostrate use of path params and arguments injection\n  // arguments being injected from event.path\n  @Lambda({\n    name: 'getById',\n    path: '/{id}',\n    method: 'get',\n    integration: 'lambda'\n  })\n  public getById(id) {\n    debug('Running get by id:', id);\n\n    return {\n      id: 'abc',\n      name: 'dcavaliere',\n      email: 'cavaliere.davide@gmail.com'\n     };\n\n  }\n\n  @Lambda({\n    name: 'error',\n    path: 'error',\n    method: 'get',\n    integration: 'lambda'\n  })\n  public error(event) {\n    debug('throwing an error');\n    // throwing an error will reject the lambda cb\n    throw new Error('something weird just happened');\n  }\n}\n\nexport { UserService };\n```\n\ncreate `api/app.ts`\n\nThe following will expose the service to be used by serverless\n\n_this should be replaced in future versions by a DI system_\n\n```typescript\n// api/app.ts\nimport { Api } from 'sls-api-decorators/lib/application';\nimport { UserService } from './user/user.service';\nimport { User } from './user/user.model';\n\n@Api({\n  // used for DI purposes\n  name : 'app',\n  // need to define factories and servises\n  factories: [User],\n  services: [UserService]\n})\nexport class App {\n\n  public services: any;\n  public factories: any;\n\n  constructor() {}\n\n}\n```\n\nrun `tsc -w \u0026` now you can call `sls invoke local -f hello`\n\nor deploy with `sls deploy`\n\nPlease note if you use the example you need to provide your own service name.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidecavaliere%2Fserverless-api-decorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidecavaliere%2Fserverless-api-decorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidecavaliere%2Fserverless-api-decorators/lists"}