Skip to main content

Extremely Stupid Simple, Blazing Fast, Get Out of your way immediately Microframework for building Python Web Applications.

Project description


Routerling

A new born baby router on it's way to being a web development platform. Routerling is a router multiplexer built with 1 goal in mind.

  • Make it stupid simple to build high performance web applications

How?

Following the unix philosophy of be the master of one thing and one thing only - Routerling has only ONE API you need to learn - Router. The API is also deliberately made consistent across the 3 different supported languages [Golang, Python, Typescript/JavaScript]. See Similarities

 

Python

from routerling import Context, HttpRequest, ResponseWriter, Router
from logging import log

def get_customer_orders(r: HttpRequest, w: ReponseWriter, s: State):
    w.headers = "go-go-gadget", ""
    w.body = '{customer: {customer_id}, orders: []}'.format(r.params.get('id'))

def change_headers(r: HttpRequest, w: ResponseWriter, s: State):
    w.headers = "go-go-gadget", "i was changed after..."

def create_customer(r: HttpRequest, w: ResponseWriter, s: State):
    print(r.body)
    w.status = 201
    w.body = '{id: 13}'


# register functions to routes
router.BEFORE('/*', lambda req, res, state: print('will run before all routes are handled'))
router.AFTER('/v1/customers/*', change_headers)
router.GET('/v1/customers/:id/orders', get_customer_orders)
router.GET('/v1/customers/:id', lambda req, res, state: log(2, state.abcxyz_variable))
router.POST('/v1/customers', create_customer)

Serve your application

uvicorn app:router

 

Request Object

  • request.body

    Body/payload of request if it exists. You can use any XML, JSON, CSV etc. library you prefer to parse r.body as you like.

    # r.body: str
    body: str = r.body
    
  • request.headers header = r.headers.get('header-name')

    All headers sent with the request.

    # r.headers: dict
    header = r.headers.get('content-type')
    
  • request.params param = r.params.get('param-name')

    Dictionary containing parts of the url that matched your route parameters i.e. /customers/:id/orders will return {'id': 45} for url /customers/45/orders.

    body: str = r.body
    

 

Response Object

  • response.abort

    Signals to routerling that you want to abort a request and ignore all GET, POST, PUT etc. handlers including all AFTER or BEFORE hooks from executing. The payload given to abort is used as the response body. Only calling w.abort() will not end function execution. You have to explicitly return from the request handler after using w.abort().

    w.abort('This is the body/payload i want to abort with')
    return
    
  • response.body

    Used to set payload/body to be sent back to the client. Returning data from a handler function does not do anything and is not used by routerling. To send something back to the client use w.body.

    w.body = b'my body'
    
  • response.headers

    Used to set headers to be sent back to the client.

    w.headers = "Content-Type", "application/json"
    w.headers = ["Authorization", "Bearer myToken"]
    

 

Context Object

Documentation coming soon

 

 

Socket Connections

Documentation coming soon

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

routerling-0.1.7.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

routerling-0.1.7-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file routerling-0.1.7.tar.gz.

File metadata

  • Download URL: routerling-0.1.7.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Darwin/20.3.0

File hashes

Hashes for routerling-0.1.7.tar.gz
Algorithm Hash digest
SHA256 abc99d3ff5c6c479d38bd0d3d296ffc0c08cc4f8cb43fdbddc8f471c5933996b
MD5 dcc955141830d5941bf11558d3248ed5
BLAKE2b-256 d33cb42c759ae04e196919e873346424dee38147e7ba3e25db2f797a226eb65d

See more details on using hashes here.

File details

Details for the file routerling-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: routerling-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Darwin/20.3.0

File hashes

Hashes for routerling-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 67b13544e52da46dab13fc0a44256eee6ebbf9ccc1ea723e1239255bd8ae868e
MD5 1f08ff6b321c925f0d7cfbd683a1dad6
BLAKE2b-256 ffb40ffcf2cc22076428a6406525fcfd32afd5c7e2fb3e6b7badf5954cd29200

See more details on using hashes here.

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