OpenQuizz
Une application de gestion des contenus pédagogiques
|
Public Member Functions | |
def | __init__ (self, app=None, prefix='', default_mediatype='application/json', decorators=None, catch_all_404s=False, serve_challenge_on_401=False, url_part_order='bae', errors=None) |
def | init_app (self, app) |
def | owns_endpoint (self, endpoint) |
def | error_router (self, original_handler, e) |
def | handle_error (self, e) |
def | mediatypes_method (self) |
def | add_resource (self, resource, *urls, **kwargs) |
def | resource (self, *urls, **kwargs) |
def | output (self, resource) |
def | url_for (self, resource, **values) |
def | make_response (self, data, *args, **kwargs) |
def | mediatypes (self) |
def | representation (self, mediatype) |
def | unauthorized (self, response) |
Data Fields | |
representations | |
urls | |
prefix | |
default_mediatype | |
decorators | |
catch_all_404s | |
serve_challenge_on_401 | |
url_part_order | |
errors | |
blueprint_setup | |
endpoints | |
resources | |
app | |
blueprint | |
The main entry point for the application. You need to initialize it with a Flask Application: :: >>> app = Flask(__name__) >>> api = restful.Api(app) Alternatively, you can use :meth:`init_app` to set the Flask application after it has been constructed. :param app: the Flask application object :type app: flask.Flask or flask.Blueprint :param prefix: Prefix all routes with a value, eg v1 or 2010-04-01 :type prefix: str :param default_mediatype: The default media type to return :type default_mediatype: str :param decorators: Decorators to attach to every resource :type decorators: list :param catch_all_404s: Use :meth:`handle_error` to handle 404 errors throughout your app :param serve_challenge_on_401: Whether to serve a challenge response to clients on receiving 401. This usually leads to a username/password popup in web browsers. :param url_part_order: A string that controls the order that the pieces of the url are concatenated when the full url is constructed. 'b' is the blueprint (or blueprint registration) prefix, 'a' is the api prefix, and 'e' is the path component the endpoint is added with :type catch_all_404s: bool :param errors: A dictionary to define a custom response for each exception or error raised during a request :type errors: dict
def __init__ | ( | self, | |
app = None , |
|||
prefix = '' , |
|||
default_mediatype = 'application/json' , |
|||
decorators = None , |
|||
catch_all_404s = False , |
|||
serve_challenge_on_401 = False , |
|||
url_part_order = 'bae' , |
|||
errors = None |
|||
) |
def add_resource | ( | self, | |
resource, | |||
* | urls, | ||
** | kwargs | ||
) |
Adds a resource to the api. :param resource: the class name of your resource :type resource: :class:`Type[Resource]` :param urls: one or more url routes to match for the resource, standard flask routing rules apply. Any url variables will be passed to the resource method as args. :type urls: str :param endpoint: endpoint name (defaults to :meth:`Resource.__name__.lower` Can be used to reference this route in :class:`fields.Url` fields :type endpoint: str :param resource_class_args: args to be forwarded to the constructor of the resource. :type resource_class_args: tuple :param resource_class_kwargs: kwargs to be forwarded to the constructor of the resource. :type resource_class_kwargs: dict Additional keyword arguments not specified above will be passed as-is to :meth:`flask.Flask.add_url_rule`. Examples:: api.add_resource(HelloWorld, '/', '/hello') api.add_resource(Foo, '/foo', endpoint="foo") api.add_resource(FooSpecial, '/special/foo', endpoint="foo")
def error_router | ( | self, | |
original_handler, | |||
e | |||
) |
This function decides whether the error occured in a flask-restful endpoint or not. If it happened in a flask-restful endpoint, our handler will be dispatched. If it happened in an unrelated view, the app's original error handler will be dispatched. In the event that the error occurred in a flask-restful endpoint but the local handler can't resolve the situation, the router will fall back onto the original_handler as last resort. :param original_handler: the original Flask error handler for the app :type original_handler: function :param e: the exception raised while handling the request :type e: Exception
def handle_error | ( | self, | |
e | |||
) |
Error handler for the API transforms a raised exception into a Flask response, with the appropriate HTTP status code and body. :param e: the raised Exception object :type e: Exception
def init_app | ( | self, | |
app | |||
) |
Initialize this class with the given :class:`flask.Flask` application or :class:`flask.Blueprint` object. :param app: the Flask application or blueprint object :type app: flask.Flask :type app: flask.Blueprint Examples:: api = Api() api.add_resource(...) api.init_app(app)
def make_response | ( | self, | |
data, | |||
* | args, | ||
** | kwargs | ||
) |
Looks up the representation transformer for the requested media type, invoking the transformer to create a response object. This defaults to default_mediatype if no transformer is found for the requested mediatype. If default_mediatype is None, a 406 Not Acceptable response will be sent as per RFC 2616 section 14.1 :param data: Python object containing response data to be transformed
def mediatypes | ( | self | ) |
Returns a list of requested mediatypes sent in the Accept header
def mediatypes_method | ( | self | ) |
Return a method that returns a list of mediatypes
def output | ( | self, | |
resource | |||
) |
Wraps a resource (as a flask view function), for cases where the resource does not directly return a response object :param resource: The resource as a flask view function
def owns_endpoint | ( | self, | |
endpoint | |||
) |
Tests if an endpoint name (not path) belongs to this Api. Takes in to account the Blueprint name part of the endpoint name. :param endpoint: The name of the endpoint being checked :return: bool
def representation | ( | self, | |
mediatype | |||
) |
Allows additional representation transformers to be declared for the api. Transformers are functions that must be decorated with this method, passing the mediatype the transformer represents. Three arguments are passed to the transformer: * The data to be represented in the response body * The http status code * A dictionary of headers The transformer should convert the data appropriately for the mediatype and return a Flask response object. Ex:: @api.representation('application/xml') def xml(data, code, headers): resp = make_response(convert_data_to_xml(data), code) resp.headers.extend(headers) return resp
def resource | ( | self, | |
* | urls, | ||
** | kwargs | ||
) |
Wraps a :class:`~flask_restful.Resource` class, adding it to the api. Parameters are the same as :meth:`~flask_restful.Api.add_resource`. Example:: app = Flask(__name__) api = restful.Api(app) @api.resource('/foo') class Foo(Resource): def get(self): return 'Hello, World!'
def unauthorized | ( | self, | |
response | |||
) |
Given a response, change it to ask for credentials
def url_for | ( | self, | |
resource, | |||
** | values | ||
) |
Generates a URL to the given resource. Works like :func:`flask.url_for`.
app |
blueprint |
blueprint_setup |
catch_all_404s |
decorators |
default_mediatype |
endpoints |
errors |
prefix |
representations |
resources |
serve_challenge_on_401 |
url_part_order |
urls |