{"id":20484577,"url":"https://github.com/tsar-boomba/megalo","last_synced_at":"2025-09-06T00:40:29.855Z","repository":{"id":58886287,"uuid":"534381574","full_name":"tsar-boomba/megalo","owner":"tsar-boomba","description":"Deno HTTP server framework focused on speed","archived":false,"fork":false,"pushed_at":"2022-10-06T14:08:19.000Z","size":58,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-03T21:15:10.740Z","etag":null,"topics":["backend","deno","http","openapi","server","typescript"],"latest_commit_sha":null,"homepage":"https://deno.land/x/megalo","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/tsar-boomba.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}},"created_at":"2022-09-08T20:25:12.000Z","updated_at":"2023-03-25T05:48:01.000Z","dependencies_parsed_at":"2022-09-20T12:02:19.851Z","dependency_job_id":null,"html_url":"https://github.com/tsar-boomba/megalo","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/tsar-boomba/megalo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsar-boomba%2Fmegalo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsar-boomba%2Fmegalo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsar-boomba%2Fmegalo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsar-boomba%2Fmegalo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsar-boomba","download_url":"https://codeload.github.com/tsar-boomba/megalo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsar-boomba%2Fmegalo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273842855,"owners_count":25177920,"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","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["backend","deno","http","openapi","server","typescript"],"created_at":"2024-11-15T16:24:05.984Z","updated_at":"2025-09-06T00:40:29.829Z","avatar_url":"https://github.com/tsar-boomba.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Megalo\n\nDeno HTTP server framework aiming for maximum speed\n\n## Example\n\n```ts\n// server.ts\nimport { Controller, Megalo } from 'https://deno.land/x/megalo/mod.ts';\nimport { cors } from 'https://deno.land/x/megalo/plugins/cors.ts';\n\nconst megalo = new Megalo({\n\t// optionally add a notFoundHandler\n\tnotFoundHandler: (req, res) =\u003e res.status(404).body(`${req.pathname} not found :(`),\n\t// optionally add an errorHandler\n\terrorHandler: (_err, _req, res, httpErr) =\u003e {\n\t\t// if NotFoundError, etc. was thrown\n\t\tif (httpErr) return res.status(httpErr.status).body(httpErr.message);\n\t\tres.status(500).body('Internal Server Error');\n\t},\n\tplugins: [cors({ origin: 'http://127.0.0.1:9000' })],\n});\n\nmegalo\n\t.get('/', { parseQuery: false }, (_req, res) =\u003e {\n\t\tres.body('hello megalo!', {\n\t\t\tstatus: 200,\n\t\t\theaders: { ['Content-Type']: 'text/html' },\n\t\t});\n\t})\n\t.post('/', (_req, res) =\u003e {\n\t\tres.body('Secret handler', { status: 200 });\n\t})\n\t.get('/sus', (_req, res) =\u003e {\n\t\tres.body('sus page', {\n\t\t\tstatus: 200,\n\t\t\theaders: { ['Content-Type']: 'text/html' },\n\t\t});\n\t})\n\t.get(/^\\/regex(\\/.*)?$/, (_req, res) =\u003e res.body(undefined, { status: 200 }))\n\t.get('/pattern/:id', ({ params }, res) =\u003e {\n\t\tres.body(`id: ${params.id}`, {\n\t\t\tstatus: 200,\n\t\t\theaders: { ['Content-Type']: 'text/html' },\n\t\t});\n\t})\n\t.post('/posted', (_req, res) =\u003e {\n\t\tres.body('you posted it :)', { status: 200 });\n\t})\n\t.controller(\n\t\tnew Controller('/users')\n\t\t\t.get('/', (_req, res) =\u003e res.body('user', { status: 200 }))\n\t\t\t.get('/:id', (req, res) =\u003e res.body(`user id: ${req.params.id}`, { status: 200 }))\n\t);\n\nconsole.log(`Startup time: ${performance.now()}ms`);\nmegalo.listen({ port: 9000, hostname: '127.0.0.1' });\n```\n\n### Start Server\n\nUse `--allow-hrtime` for more precise `performance.now()`\n\n```bash\ndeno run --allow-net --allow-hrtime --unstable server.ts\n```\n\n## Benchmarks\n\n[HTTP server benchmarks](https://github.com/denosaurs/bench#readme)\n\n## Route resolution\n\nRoutes are resolved in this order\n\n-   string literal ex. `\"/sus\"`\n-   controllers ex. `new Controller(\"/users\")`\n-   patterns ex. `\"/users/:id\"`\n-   regex ex. `/^.*\\/regex\\/.*\\/?$/`\n-   wildcard (You can only have one of these per method) `\"*\"`\n-   notFoundHandler\n\n## Hooks\n\nYou can use hooks to run functions when certain lifecycle events occur. Hooks\ncan be used on the Megalo instance or Controller instance.\n\n-   preRoute: runs before pathname is evaluated and handler is chosen\n-   preHandle: runs directly before handler\n-   postHandle: runs directly after handler (may change in the future)\n\nThe megalo instance has some exclusive hooks\n\n-   preParse: runs before anything is done, right when request is received\n-   preSend: run directly before response is sent to client, last chance to add\n    headers or whatever\n\nThis is an example on how to use hooks. If you return the res from the hook it\nwill be sent early.\n\n```ts\nimport { ForbiddenError, Megalo } from 'https://deno.land/x/megalo/mod.ts';\n\nconst megalo = new Megalo();\n\nmegalo\n\t.addHook('preRoute', (req, res) =\u003e {\n\t\t// note that all pathname will never have trailing slash, even if url does\n\t\tif (req.pathname === '/return-early') return res;\n\t\tif (req.pathname === '/forbidden') throw new ForbiddenError('not okay \u003e:(');\n\t})\n\t.get((req, res) =\u003e {\n\t\tres.status(200);\n\t});\n\nmegalo.listen({ port: 9000, hostname: '127.0.0.1' });\n```\n\n## Error Throwing\n\nYou can throw special exported errors to have the response status and body\nautomatically set.\n\n```ts\nimport { InternalServerError, Megalo } from 'https://deno.land/x/megalo/mod.ts';\n\nconst megalo = new Megalo();\n\nmegalo.get((req) =\u003e {\n\tthrow new InternalServerError({ message: 'uh oh' });\n\tres.status(200);\n});\n\nmegalo.listen({ port: 9000, hostname: '127.0.0.1' });\n```\n\n## OpenAPI Support\n\nMegalo now has support for defining OpenAPI Documentation in your code. check out `openApiExample.ts` for a small example of using it. You can check out the [example deployment](https://tsar-boomba-megalo.deno.dev/swagger).\n\n## Notes\n\nIf using serve / flash instead of listen, until\nhttps://github.com/denoland/deno/issues/15813 is resolved, in all POST, PUT, and\nPATCH routes you MUST await the body or else deno will panic.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsar-boomba%2Fmegalo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsar-boomba%2Fmegalo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsar-boomba%2Fmegalo/lists"}