{"id":26971489,"url":"https://github.com/MrPigss/DecoRouter","last_synced_at":"2025-04-03T09:05:09.892Z","repository":{"id":43365658,"uuid":"465414857","full_name":"MrPigss/DecoRouter","owner":"MrPigss","description":"FastAPI style routing for starlette","archived":false,"fork":false,"pushed_at":"2022-03-05T14:00:39.000Z","size":378,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T04:49:48.067Z","etag":null,"topics":["decorators","fastapi","starlette"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MrPigss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-02T17:59:16.000Z","updated_at":"2024-12-11T06:31:05.000Z","dependencies_parsed_at":"2022-08-20T00:41:19.393Z","dependency_job_id":null,"html_url":"https://github.com/MrPigss/DecoRouter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrPigss%2FDecoRouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrPigss%2FDecoRouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrPigss%2FDecoRouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrPigss%2FDecoRouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrPigss","download_url":"https://codeload.github.com/MrPigss/DecoRouter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246970318,"owners_count":20862509,"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":["decorators","fastapi","starlette"],"created_at":"2025-04-03T09:04:49.051Z","updated_at":"2025-04-03T09:05:09.858Z","avatar_url":"https://github.com/MrPigss.png","language":"Python","funding_links":[],"categories":["Extensions"],"sub_categories":["Routing"],"readme":"\u003cdiv id=\"top\"\u003e\u003c/div\u003e\n\n[![Issues][issues-shield]][issues-url]\n![black][black-shield]\n[![LinkedIn][linkedin-shield]][linkedin-url]\n\n\n\n\u003c!-- PROJECT LOGO --\u003e\n\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003c!-- \u003ca href=\"https://github.com/MrPigss/DecoRouter\"\u003e\n    \u003cimg src=\"images/logo.png\" alt=\"Logo\" width=\"80\" height=\"80\"\u003e\n  \u003c/a\u003e --\u003e\n\n  \u003ch2 align=\"center\"\u003estarlette_decoRouter\u003c/h3\u003e\n\n  \u003cp align=\"center\"\u003e\n    A FastAPI style router for Starlette.\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/MrPigss/DecoRouter\"\u003e\u003cstrong\u003eExplore the docs »\u003c/strong\u003e\u003c/a\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/MrPigss/DecoRouter\"\u003eView Demo\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/MrPigss/DecoRouter/issues\"\u003eReport Bug\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/MrPigss/DecoRouter/issues\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n\n\n\u003c!-- TABLE OF CONTENTS --\u003e\n\u003cdetails\u003e\n  \u003csummary\u003eTable of Contents\u003c/summary\u003e\n  \u003col\u003e\n    \u003cli\u003e\n      \u003ca href=\"#about-the-project\"\u003eAbout The Project\u003c/a\u003e\n      \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#the-good\"\u003eThe good\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#the-less-good\"\u003eThe less good\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#the-best-of-both\"\u003eThe best of both\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#contact\"\u003eContact\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#acknowledgments\"\u003eAcknowledgments\u003c/a\u003e\u003c/li\u003e\n  \u003c/ol\u003e\n\u003c/details\u003e\n\n\n\n\u003c!-- ABOUT THE PROJECT --\u003e\n## About The Project\n\n\u003c!-- [![decoRouter Screen Shot][decoRouter-screenshot]](./images/DecoRouter.png) --\u003e\n\nFastApi is a great tool for developing APIs in a quick and easy way. In their own words:\n\u003eFastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.\n\nIt is build using starlette which is in their own words:\n\u003ea lightweight ASGI framework/toolkit, which is ideal for building high performance asyncio services.\n\n\n### The good\n\nOne of the things that I love about FastAPI is how easy it is to setup different routes. Just use a decorator above the function that corresponds to that route and done.\n[![FastAPI Screen Shot][FastAPI-screenshot]](./images/FastAPI.png)\nIt's easy to see which route corresponds to which function and vice versa.\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n### The less good\n\nIn starlette you first declare different functions and then at the end of the file you map the path, allowed HTTP methods and endpoint function together.\n[![starlette Screen Shot][starlette-screenshot]](./images/Starlette.png)\n\nThis makes it easy to make mistakes as there is no way to immediately know which endoint corresponds to a certain function, unless you check the routes at the end of the file. They might not even be declared in that file at all.\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n### The best of both\n\ndecoRouter auto generates your routes for you based on decorators, just like FastAPI. The downside is that you have to import an extra module, but the added bonus of easier to read and maintain code is certainly worth it.\n[![decoRouter Screen Shot][decoRouter-screenshot]](./images/DecoRouter.png)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\n## Installation\nYou can simply install the module using pip.\n* `\u003e pip install starlette-decoRouter`\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\n## Usage\n\nTo use decoRouter you will need to know how starlette works.\ndecoRouter will not create an app for you, it will only generate the routes.\n\n_For more info regarding starlette, please refer to the [Documentation](https://www.starlette.io/)_\n\n### Example\nbelow is a basic example.  \nThere is one endpoint '`/`' which only accepts `GET` requests, and returns `{'hello': 'world'}`.\n* example.py:\n\n```python\nfrom starlette.applications import Starlette\nfrom starlette.responses import JSONResponse\nfrom decoRouter import Router\n\nrouter = Router()\n\n@router.get('/')\nasync def homepage(request):\n    return JSONResponse({'hello': 'world'})\n\n\napp = Starlette(routes=router)\n```\nThen run the application...\n\n```sh\n$ uvicorn example:app\n```\n\n---\n\n### Multiple HTTP methods\nIt's also possible to accept multiple HTTP methods for one endpoint.  \nBelow you can see one endpoint '`/`' which accepts both `POST` and `PUT` requests.\n\n```python\nfrom starlette.applications import Starlette\nfrom starlette.responses import JSONResponse\nfrom decoRouter import Router\n\nrouter = Router()\n\n@router.PUT()\n@router.POST('/')\nasync def homepage(request):\n    return JSONResponse({'hello': 'world'})\n\n\napp = Starlette(routes=router)\n```\n\nAs you can see only the last decorator has a path. It is not necessary to define it multiple times as only the last one will be used.\n\nFor example:\n```python\n@router.PUT()\n@router.POST('/')\n@router.POST('/home')\nasync def home(request):\n    pass\n```\nAbove, the second decorator will do nothing.  \nThis will result in the endpoint '`/home`' accepting both `PUT` and `POST` requests.\nThe endpoint '`/`' will return a 404.\n\nThis means that there is ONE endpoint per function.\nYou can't add multiple endpoints to the same function or vice versa.\n\n---\n\n### Multiple endpoints\nUnique endpoints are created based on the function name.  \nThe function names will have no influence over the path of the endpoint.\nIf a function with a duplicate name is created it will NOT override the original one.\nThis this means.  \n_Duplicate function names will be ignored, only the first one will be used._\n\n```python\n@router.get('/')\nasync def home(request):\n    pass\n\n@router.get('/home')\nasync def home(request):\n    pass\n```\n\nThe above will result in only one endpoint: '`/`'.  \nThe second occurence of home will be ignored\n\n\n---\n\n### Extra\nstarlette does not check for correct HTTP methods, so neither does decoRouter.\nMethods are case insensitive. `router.get()` is the same as `router.GET()` or even `router.GeT()`. \nAnd since there are no checks, things like  `router.ilasdfggb()` are perfectly fine and will not result in an error. Keep this in mind while debugging.\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- CONTACT --\u003e\n## Contact\n\nThomas - [@TEeckhout](https://twitter.com/@TEeckhout) - [LinkedIn](https://www.linkedin.com/in/thomas-eeckhout-761500181) - thomas.eeckhout@outlook.be  \nProject Link: [https://github.com/MrPigss/DecoRouter](https://github.com/MrPigss/DecoRouter)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\n\n\u003c!-- ACKNOWLEDGMENTS --\u003e\n## Acknowledgments\nThank you\n* [Starlette](https://www.starlette.io/)\n* [FastAPI](https://fastapi.tiangolo.com/)\n* [Img Shields](https://shields.io)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n## PS.\nApparently starlette still supports using decorators but these are not documented anywhere since they are deprecated since 0.13.0, see [changelog][changelog].\n\n\u003c!-- MARKDOWN LINKS \u0026 IMAGES --\u003e\n\u003c!-- https://www.markdownguide.org/basic-syntax/#reference-style-links --\u003e\n[contributors-shield]: https://img.shields.io/github/contributors/MrPigss/DecoRouter.svg?style=flat\n[contributors-url]: https://github.com/MrPigss/DecoRouter/graphs/contributors\n\n[forks-shield]: https://img.shields.io/github/forks/MrPigss/DecoRouter.svg?style=flat\n[forks-url]: https://github.com/MrPigss/DecoRouter/network/members\n\n[stars-shield]: https://img.shields.io/github/stars/MrPigss/DecoRouter.svg?style=flat\n[stars-url]: https://github.com/MrPigss/DecoRouter/stargazers\n\n[issues-shield]: https://img.shields.io/github/issues/MrPigss/DecoRouter.svg?style=flat\n[issues-url]: https://github.com/MrPigss/DecoRouter/issues\n\n[linkedin-url]: https://www.linkedin.com/in/thomas-eeckhout-761500181/\n[linkedIn-shield]: https://img.shields.io/badge/LinkedIn-blue?logo=linkedin\u0026style=flat\n\n\n[black-shield]: https://img.shields.io/badge/code%20style-black-000000.svg\n\n[decoRouter-screenshot]: images/DecoRouter.png\n[starlette-screenshot]: images/Starlette.png\n[FastAPI-screenshot]: images/FastAPI.png\n\n[changelog]: https://www.starlette.io/release-notes/#:~:text=memory%20upload%20files.-,0.13.0,style%20in%20favour%20of%20declarative%20routing%20tables%20and%20middleware%20definitions.,-0.12.12\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMrPigss%2FDecoRouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMrPigss%2FDecoRouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMrPigss%2FDecoRouter/lists"}