The congress.api.webservice Module¶
-
class
congress.api.webservice.AbstractApiHandler(path_regex)¶ Bases:
objectAbstract handler for API requests.
- Attributes:
- path_regex: The regular expression matching paths supported by this
- handler.
-
handle_request(request)¶ Handle a REST request.
- Args:
- request: A webob request object.
- Returns:
- A webob response object.
-
handles_request(request)¶ Return true iff handler supports the request.
-
class
congress.api.webservice.CollectionHandler(path_regex, model, allow_named_create=True, allow_list=True, allow_create=True, allow_update=False)¶ Bases:
congress.api.webservice.AbstractApiHandlerAPI handler for REST collection resources.
REST collections represent collections of entities in the data model, and often support the following operations:
- List elements in the collection
- Create new element in the collection
- The following less-common collection operations are NOT SUPPORTED:
- Replace all elements in the collection
- Delete all elements in the collection
-
create_member(request, id_=None)¶
-
handle_request(request)¶ Handle a REST request.
- Args:
- request: A webob request object.
- Returns:
- A webob response object.
-
list_members(request)¶
-
update_members(request)¶
-
exception
congress.api.webservice.DataModelException(error_code, description, data=None, http_status_code=400)¶ Bases:
exceptions.ExceptionCongress API Data Model Exception
Custom exception raised by API Data Model methods to communicate errors to the API framework.
-
classmethod
create(error)¶ Generate a DataModelException from an existing CongressException.
:param error has a ‘name’ field corresponding to an error_codes error-name. It may also have a ‘data’ field. Returns a DataModelException properly populated.
-
rest_response()¶
-
classmethod
-
class
congress.api.webservice.ElementHandler(path_regex, model, collection_handler=None, allow_read=True, allow_actions=True, allow_replace=True, allow_update=True, allow_delete=True)¶ Bases:
congress.api.webservice.AbstractApiHandlerAPI handler for REST element resources.
REST elements represent individual entities in the data model, and often support the following operations:
- Read a representation of the element
- Update (replace) the entire element with a new version
- Update (patch) parts of the element with new values
- Delete the element
Elements may also exhibit ‘controller’ semantics for RPC-style method invocation, however this is not currently supported.
-
action(request)¶
-
delete(request)¶
-
handle_request(request)¶ Handle a REST request.
- Args:
- request: A webob request object.
- Returns:
- A webob response object.
-
read(request)¶
-
replace(request)¶
-
update(request)¶
-
class
congress.api.webservice.SimpleDataModel(model_name)¶ Bases:
objectA container providing access to a single type of data.
-
add_item(item, params, id_=None, context=None)¶ Add item to model.
- Args:
item: The item to add to the model params: A dict-like object containing parameters
from the request query string and body.id_: The ID of the item, or None if an ID should be generated context: Key-values providing frame of reference of request
- Returns:
- Tuple of (ID, newly_created_item)
- Raises:
- KeyError: ID already exists. DataModelException: Addition cannot be performed.
-
delete_item(id_, params, context=None)¶ Remove item from model.
-
get_items(params, context=None)¶ Get items in model.
- Args:
- params: A dict-like object containing parameters
- from the request query string and body.
context: Key-values providing frame of reference of request
- Returns: A dict containing at least a ‘results’ key whose value is
- a list of items in the model. Additional keys set in the dict will also be rendered for the user.
-
update_item(id_, item, params, context=None)¶ Update item with id_ with new data.
- Args:
id_: The ID of the item to be updated item: The new item params: A dict-like object containing parameters
from the request query string and body.context: Key-values providing frame of reference of request
- Returns:
- The updated item.
- Raises:
- KeyError: Item with specified id_ not present. DataModelException: Update cannot be performed.
-
update_items(items, params, context=None)¶ Update items in the model.
- Args:
- items: A dict-like object containing new data params: A dict-like object containing parameters context: Key-values providing frame of reference of request
- Returns:
- None.
-
-
congress.api.webservice.error_response(status, error_code, description, data=None)¶ Construct and return an error response.
- Args:
- status: The HTTP status code of the response. error_code: The application-specific error code. description: Friendly G11N-enabled string corresponding to error_code. data: Additional data (not G11N-enabled) for the API consumer.
-
congress.api.webservice.original_msg(e)¶ Undo oslo-messaging added traceback to return original exception msg