{"id":48257673,"url":"https://github.com/somod-dev/somod-http-extension","last_synced_at":"2026-04-04T21:19:37.821Z","repository":{"id":161980297,"uuid":"635177062","full_name":"somod-dev/somod-http-extension","owner":"somod-dev","description":"somod extension to validate and parse http event","archived":false,"fork":false,"pushed_at":"2025-12-27T10:10:20.000Z","size":230,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-28T22:44:14.953Z","etag":null,"topics":[],"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/somod-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-05-02T06:09:17.000Z","updated_at":"2025-12-27T10:10:24.000Z","dependencies_parsed_at":"2023-12-05T17:45:37.882Z","dependency_job_id":"9f11c975-e1fd-492b-8e8b-d96054a9133b","html_url":"https://github.com/somod-dev/somod-http-extension","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/somod-dev/somod-http-extension","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somod-dev%2Fsomod-http-extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somod-dev%2Fsomod-http-extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somod-dev%2Fsomod-http-extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somod-dev%2Fsomod-http-extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/somod-dev","download_url":"https://codeload.github.com/somod-dev/somod-http-extension/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somod-dev%2Fsomod-http-extension/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31414686,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T20:09:54.854Z","status":"ssl_error","status_checked_at":"2026-04-04T20:09:44.350Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-04-04T21:19:37.120Z","updated_at":"2026-04-04T21:19:37.812Z","avatar_url":"https://github.com/somod-dev.png","language":"TypeScript","readme":"# SOMOD Http Extension\n\n---\n\nThe [SOMOD](https://somod.dev) Extension Configure HTTP routes and validate incoming HTTP Requests in Serverless Functions.\n\n\u003e The middlware in this extension works with Functions of type `HttpApi` Only.\n\n## Install\n\nInstall as an npm package in somod modules\n\n```bash\nnpm install somod-http-extension\n```\n\n## Usage\n\n### Attach the middleware to the Serverless Function\n\n```yaml\nResources:\n  MyHttpHandler:\n    Type: AWS::Serverless::Function\n    Properties:\n      CodeUri:\n        SOMOD::Function:\n          # ...\n          middlewares:\n            - module: somod-http-extension\n              resource: SomodHttpMiddleware\n      # ...\n```\n\nRefer to SOMOD's [Middleware](https://docs.somod.dev/reference/main-concepts/serverless/middlewares) reference for more information\n\n### Configure Routes and Schemas\n\nRoutes configuration for each serverless function can be provided using a yaml file at `serverless/functions/\u003cfunction_name\u003e.http.yaml`.\n\nExample:\n\n```yaml\n# serverless/functions/user.http.yaml\n\n/user/{userId}:\n  GET:\n    parameters:\n      - in: path\n        name: userId\n        schema:\n          type: string\n          maxLength: 32\n        required: true\n  POST:\n    parameters:\n      - in: path\n        name: userId\n        schema:\n          type: string\n          maxLength: 32\n        required: true\n    body:\n      parser: json\n      schema:\n        type: object\n        required: [name]\n        properties:\n          name:\n            type: string\n            maxLength: 32\n          email:\n            type: string\n            format: email\n```\n\n### Access Sanitized Request\n\nThe sanitized request can be accessed using the [middleware](https://docs.somod.dev/reference/main-concepts/serverless/middlewares)'s context using the **`somod-http-request`** key.\n\nExample:\n\n```typescript\n// serverless/functions/user.ts\n\nconst UserService = event =\u003e {\n  const request = event.somodMiddlewareContext.get(\"somod-http-request\");\n  // use request to read the data from the incoming http request\n};\n\nexport default UserService;\n```\n\nThis module also provides a utility library to create Serverless Functions with multiple routes easily. Refer to [RouteBuilder](#routeBuilder) for more details\n\n## Specification\n\n### Structure of Routes configuration file\n\nIn general, routes configuration in `\u003cfunction_name\u003e.http.yaml` file follows the below structure\n\n```yaml\n\u003cpath\u003e:\n  \u003cmethod\u003e:\n    parameters?:\n      - in: \u003c\"path\", \"query\" or \"header\"\u003e\n        name: \u003cname of the parameter\u003e\n        schema: \u003cjson schema\u003e\n        required: \u003ctrue if the parameter is mandatory\u003e\n    body?:\n      parser?: \u003c\"text\"|\"json\"|\"formdata\"\u003e. If not provided, automatically choosen based on the Content-Type Header (text is considered if automatic detection fails)\n      schema: \u003cjson schema\u003e\n```\n\nThe complete JSONSchema is available [here](/lib/routes-schema.ts)\n\n### Type of the Request object\n\nThe request object accessed using `event.somodMiddlewareContext.get(\"somod-http-request\")` has this type.\n\n```typescript\ntype Request\u003c\n  T = unknown,\n  PT extends Record\u003cstring, unknown\u003e = Record\u003cstring, unknown\u003e,\n  QT extends Record\u003cstring, unknown\u003e = Record\u003cstring, unknown\u003e,\n  HT extends Record\u003cstring, unknown\u003e = Record\u003cstring, unknown\u003e\n\u003e = {\n  route: string;\n  method: string;\n  parameters: {\n    path: PT;\n    query: QT;\n    header: HT;\n  };\n  body: T;\n};\n```\n\nThe `Request` Type is available from this module to use (import as shown below)\n\n```typescript\nimport { Request } from \"somod-http-extension\";\n```\n\n### HTTP Error Types\n\nThe validation middleware returns the following HTTP error codes\n\n- `404` - When the method and path in the incoming http request do not match any of the configured routes.\n- `400` - When the parsing or validating of the incoming request fails (following the configuration in `\u003cfunction_name\u003e.http.yaml`).\n- `500` - Any other failures.\n\n## RouteBuilder\n\nThe `RouteBuilder` is a wrapper javascript utility library to create serverless functions with multiple routes.\n\n### Using the RouteBuilder\n\n```typescript\n// serverless/function/user.ts\nimport { RouteBuilder } from \"somod-http-extension\";\n\nconst builder = new RouteBuilder();\n\nbuilder.add(\"/user/{userId}\", \"get\", getUserFunction);\nbuilder.add(\"/user/{userId}\", \"post\", updateUserFunction);\n\nexport default builder.getHandler();\n```\n\n### RouteBuilder Specification\n\nRouteBuilder has 2 methods\n\n- `add`\n\n  ```typescript\n  function add(\n    path: string,\n    method: string,\n    handler: (request: Request, event: RawEvent) =\u003e Promise\u003cResponse\u003e\n  ): void {\n    //\n  }\n  ```\n\n  The handler receives the [sanitized request object](#type-of-the-request-object) and the raw event from AWS. The handler has to return a promise which resolves to the Response object.\n\n  \u003e The Raw Event type and Response type is documented [here](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html) in the AWS specification.  \n  \u003e This module works with HTTP Payload format version 2.0 only\n\n- `getHandler`\n\n  ```typescript\n  function getHandler(): (event: RawEvent) =\u003e Promise\u003cResponse\u003e {\n    //\n  }\n  ```\n\n  handle function returns the function which is a lambda function handler\n\n## Issues\n\nThe project issues, features, and milestones are maintained in this GitHub repo.\n\nCreate issues or feature requests at https://github.com/somod-dev/somod-http-extension/issues\n\n## Contributions\n\nPlease read our [CONTRIBUTING](https://github.com/somod-dev/somod/blob/main/CONTRIBUTING.md) guide before contributing to this project.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsomod-dev%2Fsomod-http-extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsomod-dev%2Fsomod-http-extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsomod-dev%2Fsomod-http-extension/lists"}