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

Create Microservice

First of all , we create the microservice called Product Ms and its linked database ( a MongoDB database )

elastichsearch

Add Product Endpoint

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

Add Function

elastichsearch

Reference The Function In The Endpoint

After the creation of the function , we create the endpoint of adding the product and we reference the function as an input function

Execute The endpoint

We execute the endpoint and can see the result as following :

elastichsearch

Get Products List Endpoint

Finally , we will add an endpoint that transform the result of a classic get all products to list of products and their count

Add Function

elastichsearch

Reference The Function In The Endpoint

After the creation of the function , we create the endpoint of getting the products list and we reference the function as an output function

Execute The endpoint

We execute the endpoint and can see the result as following :

elastichsearch