A Flask extension that forces extremely skinny controllers.
Project description
flask-skinny
A Flask extension that forces extremely skinny controllers.
@app.route("/dogs/<int:dog_id>", methods=["POST"])
@skinny.responses({200: responses.greet_dog, 400: responses.bad_request})
@skinny.intent(intents.greet_dog)
def greet_dog(dog_id):
pass
Description
This extension contains two decorators, @skinny.intent and @skinny.responses.
@skinny.intent(callable)callable: Receivesflask.request, returnsstatus_codeandoutcome.
@skinny.responses({status_code: callable, ...})callable: Receivesflask.requestandoutcome, returnsheadersandbody.
@skinny.responses will choose an appropriate response by status_code.
Simple Usage
from flask import Flask
from flask_skinny import skinny
from random import randint
import json
def intent(request):
if randint(0, 1) == 0:
status_code = 200
outcome = "OK"
else:
status_code = 403
outcome = "Forbidden"
return status_code, outcome
def response(request, outcome):
headers = {"content-type": "application/json"}
body = json.dumps({"message": outcome}) + "\n"
return headers, body
app = Flask(__name__)
@app.route("/", methods=["GET"])
@skinny.responses({200: response, 403: response})
@skinny.intent(intent)
def index():
pass
Detailed Usage
See app.py.
Installation
$ pip install flask-skinny
Contribution
Create new Pull Request.
License
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask-skinny-0.1.2.tar.gz.
File metadata
- Download URL: flask-skinny-0.1.2.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d0dffcadb4342c1969cdd7c91d6716204ecc4bca5c322158937d1e1fed52748
|
|
| MD5 |
a1a7d86109cc715512a22a545a025f06
|
|
| BLAKE2b-256 |
54bc9502e931001949f8689d4f4a80755192deca65354956ab70f44952f05d0f
|
File details
Details for the file flask_skinny-0.1.2-py3-none-any.whl.
File metadata
- Download URL: flask_skinny-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47be312ecdc2bae44e05d49d3656f70869689730bc23a807d6ad4e013293bf02
|
|
| MD5 |
e67c4522832c81f7f95fb01ed88374fa
|
|
| BLAKE2b-256 |
bc763fc63b35a7ba3f9514261efcce1d478ae8e5f815818776a14f6ee5015d0f
|