A simple but effective Routing system for Flask projects
Explore the docs »
Report Bug
·
Request Feature
Table of Contents
easy-route is a Python 🐍 package 📦 that will allow you to define the routes for your Flask projects in a simple yet effective way.
A Route object is composed by a few configurable and extensible components:
- Middlewares
- Controller
The middleware is the first component in the Route stack.
It takes care of operations like data validation, authentication check, ...
Each route can contain zero, one or more middlewares that will be executed before the controller one by one, in insertion order.
A middleware can stop the Route execution by returning a Response object, for instance it may return a HTTP 400
response if the input data is invalid, or a HTTP 401
if the user is not authenticated.
If the middleware succeeds, it returns None
to tell the Route to go ahead with other components.
The controller is the core of every route, as it implements the logic behind the route.
After all the middlewares have been validated, the Route calls the controller and returns its result.
A Route, by definition, can contain only a single Controller.
This package containes a few dependencies, specified in requirements.txt
.
After cloning the repo, you can install the dependencies with:
pip install -r requirements
You can also install the requirements in a virtual environment:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements
To use this package in your projects you can either install the latest release from PyPi or install a specific version from sources.
To install it from PyPi you can use pip
:
pip install easy-route
You can also use pip
to install a specific version from this repo:
pip install git+https://github.com/en0mia/easy-route
Please, refer to the pip docs for details about selecting the tag, version or branch.
The usage of this package is pretty straightforward.
Firstly, you have to create a Route object:
route = Route(request, MyController())
Then you can add one or more middleware(s):
route.add_middleware(MyMiddleware())
# Or, to add more than one middleware at once:
route.add_middlewares([MyMiddleware(), SecondMiddleware()])
After the middlewares you can run the route and return its response:
return route.dispatch()
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Project Link: https://github.com/en0mia/easy-route
Kudos for this README template to othneildrew.
You can find the repo here.