BioT Interceptor Plugins
BioT Interceptor plugins are lambda code that is called before or after an API call and lets the plugin modify the call request or response accordingly. The plugins are useful when you want to modify an API request before it is processed by BioT or modify the response before it arrives to the UI.
Flow Example
Types of interceptions
There are 3 types of interceptions:
- PRE_REQUEST - intercept before executing the API code (before the request reachs the controller). Here you will be able to change the request JSON body, the query parameters, the headers, the path (which means you can navigate the call to a different API on the same service) and also fail the API call
- POST_REQUEST - intercept after executing the API code (after the controller has sent a response). Here you will be able to change the response JSON body and the http status code
- ADAPT_ENTITY - same as POST_REQUEST but this interception type is not per API but per entity. All of the APIs related to this entity (create,update,get,search,more..) that return the entity object will be intercepted if there is a subscription for this entity. Here you will be able to customize the entity(ies) that will be returned and the http status code. For CRUD or operation APIs the entities array will contain 1 object, for search API the entities array may contain zero or more objects
Subscribing to Events
To subscribe to an API, call the subscribe API of the service:
POST https://your-biot-domain.com/dispatcher/v1/hooks/interceptions/subscribe
Parameter | Description | Format |
---|---|---|
type | The type of interception. Meaning pre, post or entity interception. | Values:PRE_REQUEST,POST_REQUEST,ADAPT_ENTITY |
apiId | The API to intercept. The signature of the API made of the request type and URL signature. | Example: PATCH/organization/v1/users/patients/{id} |
entityName | Should be provided only in ADAPT_ENTITY mode. | usage-session generic-entity caregiver patient organization-user organization device command device-alert patient-alert |
endpoint | A valid URI for the platform to call when the event is triggered. Mandatory. | https://my-web-hook.com |
executionOrder | Optional parameter to determine the plugin execution order if multiple interceptors exists for the same API |
Possible interceptions
No all API calls can be intercepted, to find out which can, please use this API call
Interceptor Plugin Deployment
For detailed instructions on how to deploy an interceptor plugin click here.
Blocking a Requests/Responses
Interceptor plugins can also block the normal flow of a request or response.
To modify the response, instead of returning a success code (2XX) in the HTTP response, return a client error code (4XX) or server error code (5XX) along with the following response structure:
{
"code": "ENTITY_NOT_FOUND",
"message": "Entity with id [c36cca98-29b1-41a7-90a7-91d2540c4e2d] not found",
"serviceName": "XYZ Plugin",
"traceId": "a07a7e532f3541d8",
"environment": "develop",
"details": {
"additionalProp1": {},
"additionalProp2": {},
"additionalProp3": {}
}
}
BioT will intercept the response. If the response code doesn't belong to the 2XX family (indicating success), BioT will halt the normal flow and replace the response with the interceptor's response.
Updated 24 days ago