api.models
¶
Module Contents¶
Classes¶
A single instance of an item of a specific endpoint. |
|
An API endpoint. |
|
A collection of all available API endpoints. |
|
Attributes¶
- exception api.models.ApiException(message: str = 'Internal Server Error', exception: Exception | None = None, status_code: int = 500, headers: dict[str, str] | None = None)[source]¶
Bases:
Exception
Base class for all API exceptions.
Mainly used to ensure that all exceptions regarding the API are rendered with the correct content type.
- exception api.models.ApiInvalidParamException(message: str = 'Invalid Parameter', status_code: int = 400)[source]¶
Bases:
ApiException
Base class for all API exceptions.
Mainly used to ensure that all exceptions regarding the API are rendered with the correct content type.
- class api.models.ApiEndpointItem(app: onegov.core.Framework, endpoint: str, id: str)[source]¶
Bases:
Generic
[onegov.core.collection._M
]A single instance of an item of a specific endpoint.
Passes all functionality to the specific API endpoint and is mainly used for routing.
- property api_endpoint: ApiEndpoint[_M] | None[source]¶
- class api.models.ApiEndpoint(app: onegov.core.Framework, extra_parameters: dict[str, str | None] | None = None, page: int | None = None)[source]¶
Bases:
Generic
[onegov.core.collection._M
]An API endpoint.
API endpoints wrap collection and do some filter mapping.
To add a new endpoint, inherit from this class and provide the missing functions and properties at the bottom. Note that the collection is expected to be to provide the functionality of
onegov.core.collection.Pagination
.- property batch: dict[ApiEndpointItem[_M], onegov.core.collection._M][source]¶
Returns a dictionary with endpoint item instances and their titles.
- abstract property collection: PaginationWithById[_M, Any][source]¶
Return an instance of the collection with filters and page set.
- for_page(page: int | None) Self | None [source]¶
Return a new endpoint instance with the given page while keeping the current filters.
- for_filter(**filters: Any) typing_extensions.Self [source]¶
Return a new endpoint instance with the given filters while discarding the current filters and page.
- for_item(item: None) None [source]¶
- for_item(item: onegov.core.collection._M) ApiEndpointItem[_M]
Return a new endpoint item instance with the given item.
- get_filter(name: str, default: _DefaultT, empty: _EmptyT) str | _DefaultT | _EmptyT [source]¶
- get_filter(name: str, default: _DefaultT, empty: None = None) str | _DefaultT | None
- get_filter(name: str, default: None = None, *, empty: _EmptyT) str | _EmptyT | None
- get_filter(name: str, default: None = None, empty: None = None) str | None
Returns the filter value with the given name.
- by_id(id: onegov.core.collection.PKType) onegov.core.collection._M | None [source]¶
Return the item with the given ID from the collection.
- abstract item_data(item: onegov.core.collection._M) dict[str, Any] [source]¶
Return the data properties of the collection item as a dictionary.
- For example:
- {
‘name’: ‘Paul’, ‘age’: 40
}
- abstract item_links(item: onegov.core.collection._M) dict[str, Any] [source]¶
Return the link properties of the collection item as a dictionary. Links can either be string or a linkable object.
- For example:
- {
‘website’: ‘https://onegov.ch’, ‘friends’: FriendsApiEndpoint(app).for_item(paul), ‘home’: ApiEndpointCollection(app)
}
- class api.models.ApiEndpointCollection(app: onegov.core.Framework)[source]¶
A collection of all available API endpoints.
- endpoints() dict[str, type[ApiEndpoint[Any]]] [source]¶