Ripozo的一个扩展,它将hateoas/rest/hypermedia api带到烧瓶中
flask-ripozo的Python项目详细描述
示例
这个例子描述了一个最小的烧瓶ripozo应用程序。
fromflaskimportFlaskfromflask_ripozoimportFlaskDispatcherfromripozo.decoratorsimportapimethodfromripozo.adaptersimportSirenAdapter,HalAdapterfromripozo.resourcesimportResourceBaseclassHelloWorldViewset(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'])defhello(cls,request,*args,**kwargs):faked_response_properties={'content':'hello world'}returncls(properties=faked_response_properties)# Create the flask applicationapp=Flask(__name__)# Create the dispatcherdispatcher=FlaskDispatcher(app,url_prefix='/api')# Specify the valid response typesdispatcher.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 applicationdispatcher.register_resources(HelloWorldViewset)if__name__=='__main__':app.run()# Run the app