{"id":14984969,"url":"https://github.com/jwebcoder/mith","last_synced_at":"2025-04-10T23:14:53.590Z","repository":{"id":72769509,"uuid":"263302330","full_name":"JWebCoder/mith","owner":"JWebCoder","description":"A middleware framework for Deno's http/s server.","archived":false,"fork":false,"pushed_at":"2020-08-19T21:57:40.000Z","size":483,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T23:14:39.015Z","etag":null,"topics":["api","deno","middleware","mith"],"latest_commit_sha":null,"homepage":"https://doc.deno.land/https/deno.land/x/mith/mod.ts","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/JWebCoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"JWebCoder","patreon":"jwebcoder","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-05-12T10:14:56.000Z","updated_at":"2022-08-30T07:30:43.000Z","dependencies_parsed_at":"2023-02-26T03:15:23.450Z","dependency_job_id":null,"html_url":"https://github.com/JWebCoder/mith","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JWebCoder%2Fmith","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JWebCoder%2Fmith/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JWebCoder%2Fmith/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JWebCoder%2Fmith/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JWebCoder","download_url":"https://codeload.github.com/JWebCoder/mith/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248312134,"owners_count":21082638,"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","deno","middleware","mith"],"created_at":"2024-09-24T14:10:00.345Z","updated_at":"2025-04-10T23:14:53.582Z","avatar_url":"https://github.com/JWebCoder.png","language":"TypeScript","funding_links":["https://github.com/sponsors/JWebCoder","https://patreon.com/jwebcoder"],"categories":[],"sub_categories":[],"readme":"# Mith\n\n![mith ci](https://github.com/JWebCoder/mith/workflows/mith%20ci/badge.svg)\n[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/mith/mod.ts)\n\nA middleware framework for Deno's http/s server\n\nHighly inspired by the Express middleware system\n\nDifferently from Express, the main Mith application is only responsible to handle the middleware system, it has no routes support, and it tries to leave the request and response objects form Deno untouched as much as possible\n\n## Available middlewares\n\n- **[mith_router](https://github.com/JWebCoder/mith_router)** - router middleware\n- **cookieSession.ts** - session middleware using cookies\n- **[mith_static](https://github.com/JWebCoder/mith_static)** - static file server\n\n**Note:** These middlewares will eventually move to their own repositories to split responsibilities and improve maintenance\n\n[//]: # (For Routing, session, or any other middleware you can check our awesome-mith site of community resources.)\n\n## Usage\n\n**Basic integration**\n```typescript\nimport { Mith, NextFunction, Request, Response } from 'https://deno.land/x/mith@v0.7.0/mod.ts'\n\nconst app = new Mith()\n\napp.before(\n  async (req: Request, res: Response, next: NextFunction) =\u003e {\n    res.body.before = true\n    next()\n  }\n)\n\napp.after(\n  (req: Request, res: Response, next: NextFunction) =\u003e {\n    const encoder = new TextEncoder();\n    Deno.writeFile('./after.dat', encoder.encode(`${Deno.pid} - ${JSON.stringify(res.body)}\\n`), {append: true})\n    next()\n  }\n)\n\napp.use(\n  async (req: Request, res: Response, next: NextFunction) =\u003e {\n    const body = await req.body()\n    switch (body.type) {\n      case 'error':\n        return next(new Error('error'))\n      case 'redirect':\n        res.redirect('/')\n        break\n      case 'urlencoded':\n      case 'json':\n        res.body.test = body.type\n        break\n      default:\n        res.body.test = body\n    }\n\n    next()\n  }\n)\n\napp.error(\n  (req: Request, res: Response, next: NextFunction) =\u003e {\n    res.status = res.error.status || 500\n    res.body = res.error.message\n    next()\n  }\n)\n\nexport default app\n```\n\nRight now I'm still working on the documentation, so you can check the **example** folder for full usage examples\n\n## Multiple stacks\n\n![image](./mith.png)\n\n### app.before()\n\nIntended to be used by middleware the enhances the request or response objects. Multipart body parser for example\n\n### app.main()\n\nMain business logic of the application goes here, routing definitions for example\nUsing `app.use()` will default to the main stack if no stack is passed\n\n### app.error()\n\nThis middleware stack will be triggered if the callback function next is called with an error: `next(something)`\n\n### app.after()\n\nThis middleware stack runs after sending the response to the user, it's intended to be used with extra integrations that are not directly related to the user response. Analytics or logging for example.\n## Middleware parameters\n\n### Request\nThe request contains information about the request received\n\n#### properties:\n- **body()**\nParses the body of the request and returns it in json format\n- **query()**\nParses the query string of the request and returns an [URLSearchParams](https://developer.mozilla.org/docs/Web/API/URLSearchParams) object\n- **serverRequest**\nThe original Deno server request\n\n### Response\nThe response contains information about the response that will be sent back to the requestor.\n\n#### properties:\n- **error**\nContains the error sent when calling next(error)\n- **body**\nThe body of the response\n- **headers**\nA Headers instance which contains the headers for the response\n- **finished**\nA boolean indicating that the response is completed\n- **sent**\nA boolean indicating that the response has been already sent to the requestor\n- **send**\nSends the response to the requestor\n- **redirect**\nRedirects the user to another location\n\n### Next\nA function that triggers the next middleware in line.\n\n**Triggers the next middleware**\n```typescript\nnext()\n```\n\n**Jumps to the error middleware stack**\n```typescript\nnext([someinput])\n```\n\nOn the error middleware stack calling next([someinput]) has no effect because connection is already on the error stack","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwebcoder%2Fmith","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwebcoder%2Fmith","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwebcoder%2Fmith/lists"}