<<

NAME

ProductOpener::APIProductServices - Microservices to enrich a product object

DESCRIPTION

This module implements a microservice API for operations done on an product object.

Applications can send product data (for instance a nested list of ingredients), ask for one or more services to be executed on the input product data (for instance computing the min, max and estimated percentages of each ingredient), and get back resulting product data (possibly filtered to get only specific fields back).

INTERFACE

Request

The Routing.pm and API.pm module offer an HTTP interface of this form: POST /api/v3/product_services

The POST body is a JSON object with those fields:

services

An array list of services to perform.

Currently implemented services:

- echo : does nothing, mostly for testing - parse_ingredients_text : parse the ingredients text list and return an ingredients object - extend_ingredients : extend the ingredients object with additional information - estimate_ingredients_percent : compute percent_min, percent_max, percent_estimate for each ingredient in the ingredients object - analyze_ingredients : analyze the ingredients object and return a summary object

product

A product object

fields

An array list of fields to return. If empty, only fields that can be created or updated by the service are returned. e.g. a service to parse the ingredients text list will return the "ingredients" object.

Response

The response is in the JSON API v3 response format, with a resulting product object.

echo_service ($product_ref, $updated_product_fields_ref, $errors_ref)

Echo service that returns the input product unchanged.

Service function handlers

They will be called with the input product object, a reference to the updated fields hash, and a reference to the errors array.

product_services_api($request_ref)

Process API v3 product services requests.

<<