Reference

In class Meta we declare different resource’s options. There is a possibility to write your own behavior for certain methods .

class awokado.resource.BaseResource
class Meta
Parameters:
  • name – used for two resources connection by relation
  • model – represents sqlalchemy model or cte
  • methods – tuple of methods you want to allow
  • auth – awokado BaseAuth class for embedding authentication logic
  • skip_doc – set true if you don’t need to add the resource to documentation
  • disable_total – set false, if you don’t need to know returning objects amount in read-requests
  • select_from – provide data source here if your resource use another’s model fields (for example sa.outerjoin(FirstModel, SecondModel, FirstModel.id == SecondModel.first_model_id))
auth

alias of awokado.auth.BaseAuth

auth(*args, **kwargs) → Tuple[int, str]

this method should return (user_id, token) tuple

create(session, payload: dict, user_id: int) → dict

Create method.

You can override it to add your logic.

First of all, data is prepared for creating: Marshmallow load method for data structure deserialization and then preparing data for SQLAlchemy create a query.

Inserts data to the database (Uses bulky library if there is more than one entity to create). Saves many-to-many relationships.

Returns created resources with the help of read_handler method.

delete(session, user_id: int, obj_ids: list)

Simply deletes objects with passed identifiers.

on_delete(req: falcon.request.Request, resp: falcon.response.Response, resource_id: int = None)

Falcon method. DELETE-request entry point.

Here is a database transaction opening. This is where authentication takes place (if auth class is pointed in resource) Then delete method is run.

Parameters:
  • req – falcon.request.Request
  • resp – falcon.response.Response
on_get(req: falcon.request.Request, resp: falcon.response.Response, resource_id: int = None)

Falcon method. GET-request entry point.

Here is a database transaction opening. This is where authentication takes place (if auth class is pointed in resource) Then read_handler method is run. It’s responsible for the whole read workflow.

Parameters:
  • req – falcon.request.Request
  • resp – falcon.response.Response
on_patch(req: falcon.request.Request, resp: falcon.response.Response, *args, **kwargs)

Falcon method. PATCH-request entry point.

Here is a database transaction opening. This is where authentication takes place (if auth class is pointed in resource) Then update method is run.

Parameters:
  • req – falcon.request.Request
  • resp – falcon.response.Response
on_post(req: falcon.request.Request, resp: falcon.response.Response)

Falcon method. POST-request entry point.

Here is a database transaction opening. This is where authentication takes place (if auth class is pointed in resource) Then create method is run.

Parameters:
  • req – falcon.request.Request
  • resp – falcon.response.Response
update(session, payload: dict, user_id: int, *args, **kwargs) → dict

First of all, data is prepared for updating: Marshmallow load method for data structure deserialization and then preparing data for SQLAlchemy update query.

Updates data with bulk_update_mappings sqlalchemy method. Saves many-to-many relationships.

Returns updated resources with the help of read_handler method.

class awokado.auth.BaseAuth

CREATE = { ‘ROLE NAME HERE’: Boolean value }

Example: ‘ADMIN’: True, ‘GUEST’: False

READ, UPDATE, DELETE