xia_api.rest.RestApi
- class xia_api.rest.RestApi
Bases:
object
Definition of API Implementation of xia-universe related objects
- Url Path Full Version: https://hostname:port/prefix/resource/path_to_doc/_/field_path/action
hostname:port : Service location
prefix: fixed api prefix, /api/v1/ for example
resource: Class Type, should be case-insensitive
- path_to_doc: Locating a document
Could use /_id/id_number to search by id
Could use /field_name/field_value to search by value
/_/: a seperator to separate the document part and action part
- action_path: Action of which sub-object should be called
path could be composed by multi-level. In the case of list field, fetch by using keyword has priority.
action: the method should be called
- Main HTTP -> class method Map:
root_(post): https://hostname:port/prefix/
collection_(get, post, delete): https://hostname:port/prefix/resource
document_(get, post, delete, put, patch): https://hostname:port/prefix/resource/path_to_doc
action_post: https://hostname:port/prefix/resource/path_to_doc/_/path_to_object/action
- __init__()
Methods
__init__
()action_post
(doc_class, payload, doc_path, ...)Doing an action of a path
collection_analyze
(doc_class[, ...])Analyze Document
collection_delete
(doc_class[, acl, drop])Drop a collection
collection_get
(doc_class[, payload, acl, ...])Search Document
collection_post
(doc_class, payload[, acl])Massive document creation
document_delete
(doc_class, doc_path[, acl])Delete a document
document_get
(doc_class, doc_path[, acl, ...])Get a document
document_patch
(doc_class, payload, catalog, ...)Update some fields of a document
document_post
(doc_class, payload, doc_path)Save the new document if not exist
document_put
(doc_class, payload, doc_path[, ...])Update the whole document
root_post
(class_dict, payload[, acl])Batch operation
- classmethod action_post(doc_class: Type[Document], payload: dict, doc_path: str, action_path: str, acl=None)
Doing an action of a path
- Parameters
doc_class – Document Class
action_path – Path to action
payload – Field to be modified and its new value
doc_path – path to document, could be /_id/xxx or /field1/value1/field2/value2
acl – Access Control List
- Returns
result of the chosen method
- classmethod collection_analyze(doc_class: Type[Document], analytic_request=None, acl=None)
Analyze Document
- Parameters
doc_class – Document Class
analytic_request – Analytic Request
acl – Access Control List
- Returns
document_list
- classmethod collection_delete(doc_class: Type[Document], acl=None, drop=False)
Drop a collection
- Parameters
drop – Using Drop (Not cascade operation in that case)
acl – Access Control List
doc_class – Document Class
- Returns
document_list
- classmethod collection_get(doc_class: Type[Document], payload=None, acl=None, limit=None, id_only=False, catalog=None, lazy=True, show_hidden: bool = False)
Search Document
- Parameters
lazy – Don’t load the reference or external data if they are not loaded
catalog – Display Catalog
limit – How many documents should be returned
id_only – Only return a list of id (Accelerator when there is a search engine)
acl – Access Control List
payload – Searching payload
doc_class – Document Class
show_hidden – Show hidden field or not
- Returns
document_list, or id_list if id_only is True
- classmethod collection_post(doc_class: Type[Document], payload: list, acl=None)
Massive document creation
- Parameters
doc_class – Document Class
payload – list of document to be created
acl – Access Control List
- Returns
Display form of saved document (lazy mode forced to be true, and will return whole documents)
- classmethod document_delete(doc_class: Type[Document], doc_path: str, acl=None)
Delete a document
- Parameters
doc_path – path to document, could be /_id/xxx or /field1/value1/field2/value2
acl – Access Control List
doc_class – Document Class
- classmethod document_get(doc_class: Type[Document], doc_path: str, acl=None, catalog=None, lazy=True, show_hidden: bool = False)
Get a document
- Parameters
lazy – Don’t load the reference or external data if they are not loaded
doc_path – path to document, could be /_id/xxx or /field1/value1/field2/value2
catalog – Display Catalog
acl – Access Control List
doc_class – Document Class
show_hidden – Show hidden field or not
- Returns
Display form of the document
- classmethod document_patch(doc_class: Type[Document], payload: dict, catalog: None, doc_path: str, acl=None)
Update some fields of a document
- Parameters
doc_class – Document Class
catalog – Display Catalog
payload – Field to be modified and its new value
doc_path – path to document, could be /_id/xxx or /field1/value1/field2/value2
acl – Access Control List
- Returns
Display form of modified document (lazy mode forced to be true)
- classmethod document_post(doc_class: Type[Document], payload: dict, doc_path: str, acl=None)
Save the new document if not exist
- Parameters
doc_class – Document Class
payload – Field to be modified and its new value
doc_path – path to document, could be /_id/xxx or /field1/value1/field2/value2
acl – Access Control List
- Returns
Display form of saved document (lazy mode forced to be true, and will return whole document)
- classmethod document_put(doc_class: Type[Document], payload: dict, doc_path: str, create=False, acl=None)
Update the whole document
- Parameters
doc_class – Document Class
create – Create the document if not exist
payload – Field to be modified and its new value
doc_path – path to document, could be /_id/xxx or /field1/value1/field2/value2
acl – Access Control List
- Returns
Display form of modified document (lazy mode forced to be true, and will return whole document)
- classmethod root_post(class_dict: dict, payload: list, acl=None)
Batch operation
- Parameters
class_dict – dictionary of document classes
payload – list of operations to be performed
acl – Access Control List
- Returns
Empty message, 200 * failed: error message, 500
- Return type
successful
- Format of operation (item of payload):
name: Name of the document class
id: Document ID
op: “I”, “U”, “D”, “S”
content: content in display format