A simple Flask routing package.
Project description
easy-route🚦
A simple but effective Routing system for Flask projects
Explore the docs »
Report Bug
·
Request Feature
Table of Contents
About The Project
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
Middlewares
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.
Controllers
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.
Getting Started
Prerequisites
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
Installation
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.
Usage
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()
Contributing
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
License
Distributed under the MIT License. See LICENSE
for more information.
Contact
Project Link: https://github.com/en0mia/easy-route
This template
Kudos for this README template to othneildrew.
You can find the repo here.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for easy_route-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5b96e2e8002e458cf16c355279ae641098b659446cfe116ce38b6ec428b3733 |
|
MD5 | 14f2cd8744b00629d8b305905d4d19d3 |
|
BLAKE2b-256 | a81906095cfd1ebdf5e5d63b9b33388320c388ac2e1cc7850cc1d4f8ccac3cdb |