Manage Functions
One of the best features of Grizzly API is the ability to add a function to add some business logic or transformation of the endpoint input or output.
The function can be :
- A Javascript Function
- An AWS Lambda Function
- OpenFaas Serverless Function
In this tutorial , we will create a microservice (Product MS) which use functions to add TVA to any added product and in the get of all products we add the count of products in the result
First of all , we create the microservice called Product Ms and its linked database ( a MongoDB database )
In this step , we will add an endpoint that add a product and call an input fuction to apply TVA to the price of the product
After the creation of the function , we create the endpoint of adding the product and we reference the function as an input function
We execute the endpoint and can see the result as following :
Finally , we will add an endpoint that transform the result of a classic get all products to list of products and their count
After the creation of the function , we create the endpoint of getting the products list and we reference the function as an output function
We execute the endpoint and can see the result as following :