{"id":25491571,"url":"https://github.com/fatihtatoglu/tat-router","last_synced_at":"2025-11-08T18:30:21.214Z","repository":{"id":150423275,"uuid":"622339697","full_name":"fatihtatoglu/tat-router","owner":"fatihtatoglu","description":"A lightweight routing library.","archived":false,"fork":false,"pushed_at":"2023-04-22T23:20:36.000Z","size":146,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-15T00:30:59.580Z","etag":null,"topics":["http","library","router","routing"],"latest_commit_sha":null,"homepage":"https://blog.tatoglu.net/projeler/","language":"JavaScript","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/fatihtatoglu.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}},"created_at":"2023-04-01T20:20:04.000Z","updated_at":"2023-09-05T12:33:29.000Z","dependencies_parsed_at":"2023-05-18T00:31:35.806Z","dependency_job_id":null,"html_url":"https://github.com/fatihtatoglu/tat-router","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"894262b3f15488515ee789edfaa171d37ebcb1d2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatihtatoglu%2Ftat-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatihtatoglu%2Ftat-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatihtatoglu%2Ftat-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatihtatoglu%2Ftat-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fatihtatoglu","download_url":"https://codeload.github.com/fatihtatoglu/tat-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239558932,"owners_count":19658934,"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":["http","library","router","routing"],"created_at":"2025-02-18T22:18:17.435Z","updated_at":"2025-11-08T18:30:19.623Z","avatar_url":"https://github.com/fatihtatoglu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TAT Router\n\nTAT Router is a lightweight Node.js library for handling HTTP requests based on the URL path and HTTP method.\n\n## Installation\n\n```js\nnpm install tat-router\n```\n\n## Usage\n\n### Creating a router instance\n\n```js\nconst Router = require(\"router\");\n\nconst router = new Router((res) =\u003e {\n  res.writeHead(404, { \"Content-Type\": \"text/plain\" });\n  res.write(\"404 - Not found!\")\n  res.end();\n});\n```\n\n### Adding routes\n\n```js\nrouter.add(\"GET\", \"/\", (res)=\u003e{\n  res.writeHead(200, {\"Content-Type\": \"text/plain\"});\n  res.write(\"Hello world!\");\n  res.end();\n});\n\nrouter.add(\"GET\", \"/users/:name\", (res, params) =\u003e {\n  const name = params.name;\n\n  res.writeHead(200, {\"Content-Type\": \"text/plain\"});\n  res.write(`Hello ${name}!`);\n  res.end();\n});\n\nrouter.add(\"GET\", \"/users/:userId/posts/:postId?\", (res, params)=\u003e{\n  const userId = params.userId;\n  const postId = params.postId || \"latest\";\n\n  res.writeHead(200, { \"Content-Type\": \"application/json\" });\n  res.write(`{userId: \"${userId}\", postId: \"${postId}\"}`);\n  res.end();\n});\n```\n\n### Handling requests\n\n```js\nconst req = {\n  method: \"GET\",\n  url: \"http://localhost\"\n};\n\nrouter.navigate(req, res);\n// Hello world!\n```\n\n```js\nconst req = {\n  method: \"GET\",\n  url: \"http://localhost/users/fatih\"\n};\n\nrouter.navigate(req, res);\n// Hello fatih!\n```\n\n```js\nconst req = {\n  method: \"GET\",\n  url: \"http://localhost/users/12/posts/\"\n};\n\nrouter.navigate(req, res);\n// {userId: \"12\", postId: \"latest\"}\n```\n\n```js\nconst req = {\n  method: \"GET\",\n  url: \"http://localhost/users/12/posts/34\"\n};\n\nrouter.navigate(req, res);\n// {userId: \"12\", postId: \"34\"}\n```\n\n### Connecting with HTTP module\n\n```js\nhttp.createServer((req, res) =\u003e {\n    router.navigate(req, res);\n}).listen(3000);\n```\n\n## API\n\n### Router(notFoundHandler)\n\n- `notFoundHandler`: Function to be executed when no matching route is found.\n\nRepresents a router that can handle HTTP requests with specified routes and methods.\n\n### router.add(method, pattern, handler)\n\n- `method`: HTTP method of the route.\n- `pattern`: URL path of the route (e.g., \"/users/:id\").\n- `handler`: Function to be executed when the route is matched.\n\nAdds a new route to the router with specified method, path and handler.\n\n### router.navigate(method, url)\n\n- `req`: The IncomingMessage object represents the request to the server.\n- `res`: The ServerResponse object represents the writable stream back to the client.\n\nNavigates to the route that matches.\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatihtatoglu%2Ftat-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffatihtatoglu%2Ftat-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatihtatoglu%2Ftat-router/lists"}