OpenQuizz
Une application de gestion des contenus pédagogiques
Api Class Reference
Inheritance diagram for Api:
Collaboration diagram for Api:

Public Member Functions

def __init__ (self, app=None, version='1.0', title=None, description=None, terms_url=None, license=None, license_url=None, contact=None, contact_url=None, contact_email=None, authorizations=None, security=None, doc='/', default_id=default_id, default='default', default_label='Default namespace', validate=None, tags=None, prefix='', ordered=False, default_mediatype='application/json', decorators=None, catch_all_404s=False, serve_challenge_on_401=False, format_checker=None, **kwargs)
 
def init_app (self, app, **kwargs)
 
def __getattr__ (self, name)
 
def register_resource (self, namespace, resource, *urls, **kwargs)
 
def output (self, resource)
 
def make_response (self, data, *args, **kwargs)
 
def documentation (self, func)
 
def render_root (self)
 
def render_doc (self)
 
def default_endpoint (self, resource, namespace)
 
def get_ns_path (self, ns)
 
def ns_urls (self, ns, urls)
 
def add_namespace (self, ns, path=None)
 
def namespace (self, *args, **kwargs)
 
def endpoint (self, name)
 
def specs_url (self)
 
def base_url (self)
 
def base_path (self)
 
def __schema__ (self)
 
def errorhandler (self, exception)
 
def owns_endpoint (self, endpoint)
 
def error_router (self, original_handler, e)
 
def handle_error (self, e)
 
def as_postman (self, urlvars=False, swagger=False)
 
def payload (self)
 
def refresolver (self)
 
def mediatypes_method (self)
 
def mediatypes (self)
 
def representation (self, mediatype)
 
def unauthorized (self, response)
 
def url_for (self, resource, **values)
 

Data Fields

 version
 
 title
 
 description
 
 terms_url
 
 contact
 
 contact_email
 
 contact_url
 
 license
 
 license_url
 
 authorizations
 
 security
 
 default_id
 
 ordered
 
 tags
 
 error_handlers
 
 models
 
 format_checker
 
 namespaces
 
 default_namespace
 
 ns_paths
 
 representations
 
 urls
 
 prefix
 
 default_mediatype
 
 decorators
 
 catch_all_404s
 
 serve_challenge_on_401
 
 blueprint_setup
 
 endpoints
 
 resources
 
 app
 
 blueprint
 

Detailed Description

The main entry point for the application.
You need to initialize it with a Flask Application: ::

>>> app = Flask(__name__)
>>> api = Api(app)

Alternatively, you can use :meth:`init_app` to set the Flask application
after it has been constructed.

The endpoint parameter prefix all views and resources:

    - The API root/documentation will be ``{endpoint}.root``
    - A resource registered as 'resource' will be available as ``{endpoint}.resource``

:param flask.Flask|flask.Blueprint app: the Flask application object or a Blueprint
:param str version: The API version (used in Swagger documentation)
:param str title: The API title (used in Swagger documentation)
:param str description: The API description (used in Swagger documentation)
:param str terms_url: The API terms page URL (used in Swagger documentation)
:param str contact: A contact email for the API (used in Swagger documentation)
:param str license: The license associated to the API (used in Swagger documentation)
:param str license_url: The license page URL (used in Swagger documentation)
:param str endpoint: The API base endpoint (default to 'api).
:param str default: The default namespace base name (default to 'default')
:param str default_label: The default namespace label (used in Swagger documentation)
:param str default_mediatype: The default media type to return
:param bool validate: Whether or not the API should perform input payload validation.
:param bool ordered: Whether or not preserve order models and marshalling.
:param str doc: The documentation path. If set to a false value, documentation is disabled.
            (Default to '/')
:param list decorators: Decorators to attach to every resource
:param bool catch_all_404s: Use :meth:`handle_error`
    to handle 404 errors throughout your app
:param dict authorizations: A Swagger Authorizations declaration as dictionary
:param bool serve_challenge_on_401: Serve basic authentication challenge with 401
    responses (default 'False')
:param FormatChecker format_checker: A jsonschema.FormatChecker object that is hooked into
    the Model validator. A default or a custom FormatChecker can be provided (e.g., with custom
    checkers), otherwise the default action is to not enforce any format validation.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  app = None,
  version = '1.0',
  title = None,
  description = None,
  terms_url = None,
  license = None,
  license_url = None,
  contact = None,
  contact_url = None,
  contact_email = None,
  authorizations = None,
  security = None,
  doc = '/',
  default_id = default_id,
  default = 'default',
  default_label = 'Default namespace',
  validate = None,
  tags = None,
  prefix = '',
  ordered = False,
  default_mediatype = 'application/json',
  decorators = None,
  catch_all_404s = False,
  serve_challenge_on_401 = False,
  format_checker = None,
**  kwargs 
)

Member Function Documentation

◆ __getattr__()

def __getattr__ (   self,
  name 
)

◆ __schema__()

def __schema__ (   self)
The Swagger specifications/schema for this API

:returns dict: the schema as a serializable dict

◆ add_namespace()

def add_namespace (   self,
  ns,
  path = None 
)
This method registers resources from namespace for current instance of api.
You can use argument path for definition custom prefix url for namespace.

:param Namespace ns: the namespace
:param path: registration prefix of namespace

◆ as_postman()

def as_postman (   self,
  urlvars = False,
  swagger = False 
)
Serialize the API as Postman collection (v1)

:param bool urlvars: whether to include or not placeholders for query strings
:param bool swagger: whether to include or not the swagger.json specifications

◆ base_path()

def base_path (   self)
The API path

:rtype: str

◆ base_url()

def base_url (   self)
The API base absolute url

:rtype: str

◆ default_endpoint()

def default_endpoint (   self,
  resource,
  namespace 
)
Provide a default endpoint for a resource on a given namespace.

Endpoints are ensured not to collide.

Override this method specify a custom algoryhtm for default endpoint.

:param Resource resource: the resource for which we want an endpoint
:param Namespace namespace: the namespace holding the resource
:returns str: An endpoint name

◆ documentation()

def documentation (   self,
  func 
)
A decorator to specify a view funtion for the documentation

◆ endpoint()

def endpoint (   self,
  name 
)

◆ error_router()

def error_router (   self,
  original_handler,
  e 
)
This function decides whether the error occured in a flask-restplus
endpoint or not. If it happened in a flask-restplus 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-restplus endpoint but
the local handler can't resolve the situation, the router will fall
back onto the original_handler as last resort.

:param function original_handler: the original Flask error handler for the app
:param Exception e: the exception raised while handling the request

◆ errorhandler()

def errorhandler (   self,
  exception 
)
A decorator to register an error handler for a given exception

◆ get_ns_path()

def get_ns_path (   self,
  ns 
)

◆ handle_error()

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 Exception e: the raised Exception object

◆ init_app()

def init_app (   self,
  app,
**  kwargs 
)
Allow to lazy register the API on a Flask application::

>>> app = Flask(__name__)
>>> api = Api()
>>> api.init_app(app)

:param flask.Flask app: the Flask application object
:param str title: The API title (used in Swagger documentation)
:param str description: The API description (used in Swagger documentation)
:param str terms_url: The API terms page URL (used in Swagger documentation)
:param str contact: A contact email for the API (used in Swagger documentation)
:param str license: The license associated to the API (used in Swagger documentation)
:param str license_url: The license page URL (used in Swagger documentation)

◆ make_response()

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

◆ mediatypes()

def mediatypes (   self)
Returns a list of requested mediatypes sent in the Accept header

◆ mediatypes_method()

def mediatypes_method (   self)
Return a method that returns a list of mediatypes

◆ namespace()

def namespace (   self,
args,
**  kwargs 
)
A namespace factory.

:returns Namespace: a new namespace instance

◆ ns_urls()

def ns_urls (   self,
  ns,
  urls 
)

◆ output()

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

◆ owns_endpoint()

def owns_endpoint (   self,
  endpoint 
)
Tests if an endpoint name (not path) belongs to this Api.
Takes into account the Blueprint name part of the endpoint name.

:param str endpoint: The name of the endpoint being checked
:return: bool

◆ payload()

def payload (   self)
Store the input payload in the current request context

◆ refresolver()

def refresolver (   self)

◆ register_resource()

def register_resource (   self,
  namespace,
  resource,
urls,
**  kwargs 
)

◆ render_doc()

def render_doc (   self)
Override this method to customize the documentation page

◆ render_root()

def render_root (   self)

◆ representation()

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

◆ specs_url()

def specs_url (   self)
The Swagger specifications absolute url (ie. `swagger.json`)

:rtype: str

◆ unauthorized()

def unauthorized (   self,
  response 
)
Given a response, change it to ask for credentials

◆ url_for()

def url_for (   self,
  resource,
**  values 
)
Generates a URL to the given resource.

Works like :func:`flask.url_for`.

Field Documentation

◆ app

app

◆ authorizations

authorizations

◆ blueprint

blueprint

◆ blueprint_setup

blueprint_setup

◆ catch_all_404s

catch_all_404s

◆ contact

contact

◆ contact_email

contact_email

◆ contact_url

contact_url

◆ decorators

decorators

◆ default_id

default_id

◆ default_mediatype

default_mediatype

◆ default_namespace

default_namespace

◆ description

description

◆ endpoints

endpoints

◆ error_handlers

error_handlers

◆ format_checker

format_checker

◆ license

license

◆ license_url

license_url

◆ models

models

◆ namespaces

namespaces

◆ ns_paths

ns_paths

◆ ordered

ordered

◆ prefix

prefix

◆ representations

representations

◆ resources

resources

◆ security

security

◆ serve_challenge_on_401

serve_challenge_on_401

◆ tags

tags

◆ terms_url

terms_url

◆ title

title

◆ urls

urls

◆ version

version

The documentation for this class was generated from the following file: