Skip to main content

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

Contributors Forks Stargazers Issues MIT License

Quality Gate Status Coverage Security Rating

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact

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.

(back to top)

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.

(back to top)

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

(back to top)

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.

(back to top)

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()

(back to top)

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

Project Link: https://github.com/en0mia/easy-route

This template

Kudos for this README template to othneildrew.

You can find the repo here.

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easy_route-0.0.2.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

easy_route-0.0.2-py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page