MetaResource¶
- class flask_restful_dbbase.resources.MetaResource[source]¶
Bases:
Resource
This class enables documentation for a model resource.
Class variables:
resource_class: This is the model resource that you wish to documnent.
url_prefix: Like with the ModelResource class, this prefix can be used to create a url for the documentation.
url_name: This is the final part of a url for creating a url. It defaults to a name of ‘meta’.
Both the url_prefix and url_name come into play only upon initial configuration.
Methods
as_view
(name, *class_args, **class_kwargs)Convert the class into a view function that can be registered for a route.
dispatch_request
(*args, **kwargs)The actual view function behavior.
get
()This function is the request.GET method for the meta resource URL.
get_urls
()This function returns a default url for the resource.
Attributes
decorators
A list of decorators to apply, in order, to the generated view function.
init_every_request
Create a new instance of this view class for every request by default.
method_decorators
The methods this view is registered for.
provide_automatic_options
Control whether the
OPTIONS
method is handled automatically.representations
This is the resource class to be documented
This name can be used to make the default URL for the meta resource.
This is the default prefix to be used for the URL.
- resource_class = None¶
This is the resource class to be documented
- url_prefix = 'meta'¶
This is the default prefix to be used for the URL.
- methods = {'GET'}¶
The methods this view is registered for. Uses the same default (
["GET", "HEAD", "OPTIONS"]
) asroute
andadd_url_rule
by default.
- url_name = None¶
This name can be used to make the default URL for the meta resource.
- get()[source]¶
This function is the request.GET method for the meta resource URL.
- Parameters:
method – (str) : can specify only a specific method of the resource
documented (to be) –
put. (such as get or) –
filter – (str) : the details of the table
- Returns:
meta – (json) : The documentation
- classmethod get_urls()[source]¶
This function returns a default url for the resource. To keep consistency with the get_urls functions in other resources, it returns the url in a list, even though there would never be more than one.
The approach enables a code consistent approach when using the api.add_resource function.
Example:
api.add_resource(BookResource, *BookResource.get_urls()) api.add_resource(BookCollection, *BookCollection.get_urls()) api.add_resource(BookMetaResource, *BookMetaResource.get_urls()) api.add_resource(BookMetaCollection, *BookMetaCollection.get_urls())
Default URLS: /books /books/<int:id> /meta/books/single /meta/books/collection
Bear in mind that the get_urls function is only for convenience when adding the resource the api.