farmOS / farmOS.py

A Python library for interacting with farmOS over API.
GNU General Public License v3.0
27 stars 12 forks source link

Add support for subrequests #43

Closed paul121 closed 3 years ago

paul121 commented 3 years ago

Why

The Drupal Subrequests module allows multiple, dependent or independent requests to be defined in a "blueprint". The blueprint is sent to the server in a single POST (or query string encoded GET request) to /subrequests, where the server performs each request and returns a single multipart/related response containing the result of each individual sub-request.

This enables more complex API operations to be completed in a single step. For example, creating a new asset and immediately creating a movement log to locate the asset. Subrequests would also help API users with creating Logs that have multiple quantities. This works by allowing response values in later requests via JSON Paths.

Implementation Details

Proposed resolution

paul121 commented 3 years ago

One clarification: Authorization headers are not needed for each individual sub-request. They are run in the same session as the initial request that is sent to /subrequests

paul121 commented 3 years ago

Added this in v1.0.0-alpha.2: https://github.com/farmOS/farmOS.py/releases/tag/v1.0.0-alpha.2

2: Extra: consider creating client.resource.endpoint(type, bundle, id=None, params=None) and client.log.endpoint(bundle, id=None, params=None) methods for building correct API endpoints that include IDs and query parameters.

3: Extra: create helper methods for common tasks eg: client.subrequests.createLog(references = []) (tbd...)

I think these would be nice features but lets wait to add these until later on as use cases further develop.