Important
Always use route names using helpers to generate URLs. Hard-coded URLs must not be found in the code whether relative, or absolute, in templates, models or views. To generate route path, you must use the route_path() method from the Request class. It takes a route name and resource IDs and generates the URL:
>>> route_path('user_transactions', user_id=3, id=7)
'/users/3/transactions/7'
Follows same conventions as route names, with the following changes:
Resource name use CamelCase.
All views are suffixed with View.
The collection name of the served resource (the leaf) is always used, e.g.:
URL |
Route name |
View |
---|---|---|
/users/12/transactions/14 |
user_transactions |
UserTransactionsView |
/users |
users |
UsersView |
A view class may define the following methods:
See API Documentation for the relation between HTTP verbs and Python view methods.
Notes on View methods and HTTP methods.
If derived from:
BaseView Using include param in resource.add() will tell yarhp which actions must be implemented. AttributeError will be raised if one of the icnluded actions are not defined in your view. Using exclude will tell yarhp that the current resource does not support excluded actions and thus 405 Method Not Allowed will be raised instead of AttributeError.
SQLAView default index, show and delete methods are implemented and can be overwritten in your view. Note that the defaults work currently only for top level resources.
DynamoDBView default create update index show delete methods are implemented. Works only for top level resources.
Using include/exlude params in resource.add() will have similar to 1) behavior, that is raise AttributeError if action is in include list but not implemented (except the default methods) and raise 405 if action is in exclude list.
By default all methods listed above are included.