An extension for ripozo and that brings HATEOAS/REST/Hypermedia apis to flask
Project description
flask-ripozo
This package provides a dispatcher for ripozo so that you can integrate ripozo with Flask. As with all dispatchers it is simply for getting the request arguments and appropriately routing them to the various resources for handling.
Check out the tutorial.
Or maybe the ripozo documentation.
Example
This example describes a minimal flask-ripozo application.
from flask import Flask
from flask_ripozo import FlaskDispatcher
from ripozo.decorators import apimethod
from ripozo.adapters import SirenAdapter, HalAdapter
from ripozo.resources import ResourceBase
class HelloWorldViewset(ResourceBase):
resource_name = 'myresource' # The name of the resource. This will be appended to
# the _namespace to complete the url.
# The decorator indicates that the base url will be used
# and that it will be registered for GET requests
# a GET request to /api/myresource would be dispatched to this
# method and handled here
@apimethod(methods=['GET'])
def hello(cls, request, *args, **kwargs):
faked_response_properties = {'content': 'hello world'}
return cls(properties=faked_response_properties)
# Create the flask application
app = Flask(__name__)
# Create the dispatcher
dispatcher = FlaskDispatcher(app, url_prefix='/api')
# Specify the valid response types
dispatcher.register_adapters(SirenAdapter, HalAdapter)
# This will register all of the apimethod decorated methods in
# this class specified. In this case it adds the /api/myresource GET
# route to the application
dispatcher.register_resources(HelloWorldViewset)
if __name__ == '__main__':
app.run() # Run the app
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
flask-ripozo-1.0.4.tar.gz
(9.1 kB
view details)
File details
Details for the file flask-ripozo-1.0.4.tar.gz
.
File metadata
- Download URL: flask-ripozo-1.0.4.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 794aaca8b2442efcf196cb0dfe2bf341e9653a2047b1275b499c75239983385b |
|
MD5 | 0e85d474cf96d8c19f6edc6f1518402e |
|
BLAKE2b-256 | 81b6b655736462bbfae7710c10180cf59a6e35fd8564346762cc1d4dc9a89eed |