Light-weight Python framework for building REST APIs.
Project description
cleaREST
Light-weight Python framework for building REST APIs
WSGI
minimalistic
easy to use
advanced variables processing
URL Routing
is done by decorating your handling function with one of these decorators:
@GET
@POST
only one argument is required (url to handle) ie:
@GET("/my/awesome/url") def my_function(): ...
optionally you can specify successful http result status (default is HTTP_OK) ie:
@GET("/my/awesome/url", status=HTTP_CREATED) def my_function(): ...
list of status tuples:
HTTP_OK
HTTP_CREATED
Variables
GET variables from query string
POST variables can be send as:
application/x-www-form-urlencoded
multipart/form-data
application/json
url path variables (identifier inside curly brackets) ie:
@GET("/my/awesome/url/{variable}") def my_function(variable): ...
Parsing
per parameter parsing function assigned as default value ie:
@GET("/my/awesome/url") def my_function(myid=int): ...
optional parameter:
@GET("/my/awesome/url") def my_function(myid=(int, 0)): ...
reduction multiple into one:
@GET("/my/awesome/url") def my_function(user_id=lambda user, password: login): ...
Returning data
build-in support:
Class |
Content-type |
---|---|
str |
text/plain |
dict |
application/json |
minidom |
application/xml |
etree |
application/xml |
you can also register any custom data-type or override table above with:
register_content_type(type_, content_type, handler)
Errors
to return a http error raise one of these exceptions:
HttpBadRequest
HttpNotFound
HttpUnsupportedMediaType
HttpNotImplemented
ie:
@GET("/my/awesome/url") def my_function(myid=int): if myid == -1: raise HttpNotFound() ...
Examples:
GET Hello world:
from wsgiref.simple_server import make_server from clearest import application, GET @GET("/") def hello(): return "hello world!" httpd = make_server("", 8000, application) httpd.serve_forever()
Output:
curl localhost:8000
hello world!
POST var:
from wsgiref.simple_server import make_server from clearest import application, POST @POST("/") def hello(what): return "hello {what}!".format(what=what) httpd = make_server("", 8000, application) httpd.serve_forever()
Output:
curl –data “what=world” localhost:8000
hello world!
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 cleaREST-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75112430bd0c64153b7689152e557b1519e9224c697508f0d38cf9317a594c3a |
|
MD5 | 0de0689ee2e1d21669ed95a1a5d38266 |
|
BLAKE2b-256 | 7c80ce40c13a316d0283ee14f4634670fd23dd22464c30644c98c9a8d344644b |