Grizzly API Documentation / Grizzly API / Manage Microservices / Endpoints on the fly Tutorial

Endpoints on the fly Tutorial

Create your endpoints while developing your frontend application

In this section we are going to present how you can throught our application create your custom endpoints directly while developing your frontend application. In this part we’ll consider that you have created your microservice with the Grizzly Api CLI or the website

Requirements

In this part you need to have :
ApiKey this key is provided in two ways :

  • With the website in the user details section.


    Api Key
  • If you are using the Grizzly API CLI you will find it in C:\Users<userName>\grizzly_key.config, the content of this file is your apiKey.

The Runtime url you can obtain this url by :

  • The website in the user details section.


    get_url
  • If you are using the Grizzly API CLI you can use this command: grizzly export version --microservice Products --version 1.0.1

Congratulations now you have all the requirements to benefit from this awesome feature.

Writing Http requests

In this part we are going to specify the four most common Http method (GET / POST / PUT / DELETE) how to use them in the endpoint on the fly creation respecting the openAPi specifications.

POST

To create an endpoint POST you have to specify the url and the body

  • URL : You are going to need the runtime url then you have to add the path which going to be in most cases the collection name for example : https://app.grizzly-api.com/runtime/5f87ed592e4bc80001219820/products. in this example considering that we have a microservice called Products we assumed that you are going to post a product object so we added /products to the runtime url.
  • Body : you can post your JSON object, we haven’t any restriction in attributes that you may add.
  • Result : As a result of this request we are going to return the saved object and will add an attribute _id to it.

In this exemple we are going to show how to post a product using postman as a tool using our apiKey

post-exemple

GET

To create an endpoint GET you have to specify the url and the body and the query

Usually to find all elements of a collection we use the GET request :

  • URL : You are going to need the runtime url then you have to add the path which going to be in most cases the collection name for example : https://app.grizzly-api.com/runtime/5f87ed592e4bc80001219820/products. in this example we consider that we have a microservice called Products we assumed that you are going to get the products already saved so we added /products to the runtime url.
  • Result : As a result of this request we are going to return all the saved object in the mentioned collection

In this example we are going to show how to post a product using postman as a tool using our apiKey

get-exemple

Usually to find all elements of a collection we use the GET request :

  • URL : You are going to need the runtime url then you have to add the path which going to be in most cases the collection name and the value of the path variable that we are passing for example : https://app.grizzly-api.com/runtime/5f87ed592e4bc80001219820/products/apple. in this example we consider that we have a microservice called Products we assumed that you are going to get the products with the name apple so we added /products/apple to the runtime url.
  • Query : we always add the query to the header of our request and it respects the following pattern :
 {<attribute_name>:%<rank_of_attribute_inPath>} 

in this exemple we are feching the products with the name : apple and the path is /products/apple so the rank of the parameter apple is 1 in this path so the query will be as following

query={name:%1}
  • Result : As a result of this request we are going to return all the products with the name apple.

In this example we are going to show how to post a product using postman as a tool using our apiKey

get-attribute-exemple

  • URL : You are going to need the runtime url then you have to add the path which going to be in most cases the collection name and the values of the path variables that we are passing for example : https://app.grizzly-api.com/runtime/5f87ed592e4bc80001219820/products/apple/fruits. in this example we consider that we have a microservice called Products we assumed that you are going to get the products with the name apple and the type fruit so we added /products/apple/fruit to the runtime url.
  • Query : we always add the query to the header of our request and it respects the following pattern:
{$operator:[{<attribute_name_1>:%<rank_of_attribute_1_inPath>},{<attribute_name_2>:%<rank_of_attribute_2_inPath>}]}

in this example we are feching the products with the name : apple and type : fruit and the path is /products/apple/fruit so the rank of the parameter apple is the first in this path and fruit is the second and the operator is $and, so the query will be as following :

query={$and:[{name:%1},{type:%2}]}
  • Result : As a result we are going to return all the products with the name apple and type fruits
  • Operators :The supported operators are : $and , $or

In this exemple we are going to show how to post a product using postman as a tool using our apiKey

get-expression-exemple

  • URL : You are going to need the runtime url then you have to add the path which is going to be in most cases the collection name and the value of the path variable that we are passing for example : https://app.grizzly-api.com/runtime/5f87ed592e4bc80001219820/products/1000. in this example considering we have a microservice called Products, we assumed that you are going to get the products with the price is greater than 1000 so we added /products/1000 to the runtime url.
  • Query : we always add the query to the header of our request and it respects the following pattern :
 {<attribute_name>:{$operator:%<rank_of_attribute_inPath>}} 

in this example we are feching the products with the price is greater than : 1000 and the path is /products/1000 so the rank of the parameter 1000 is the first in the path as a result the query will be as following

query={price:{$gt:%1}}
  • Result : As a result of this request we are going to return all the products with the price higher than 1000
  • Operators :The supported operators for comparasion are $gt for greater than, $lt for less than , $gte for greater or equal , $lte for less or equal

In this example we are going to show how to post a product using postman as a tool using our apiKey

get-expression-exemple

PUT

To create an endpoint PUT you have to specify the url and the body

  • URL : You are going to need the runtime url then you have to add the path which going to be in most cases the collection name for example : https://app.grizzly-api.com/runtime/5f87ed592e4bc80001219820/products. in this example considering we have a microservice called Products we assumed that you are going to update a product so we added /products to the runtime url.
  • Body : You pass the object to update
  • Result : As a result of this request we are going to return the updated object
    In this example we are going to show how to post a product using postman as a tool using our apiKey

PUT-exemple

DELETE

To create an endpoint DELETE you have to specify the url and the body and the query

Usually to delete an element from a collection we use the DELETE request :

  • URL : You are going to need the runtime url then you have to add the path which going to be in most cases the collection name and the value of the path variable that we are passing for example : https://app.grizzly-api.com/runtime/5f87ed592e4bc80001219820/products/apple. in this example considering we have a microservice called Products we assumed that you are going to get the products with the name apple so we added /products/apple to the runtime url.
  • Query : we always add the query to the header of our request and it respects the following pattern :
 {<attribute_name>:%<rank_of_attribute_inPath>} 

in this example we are deleting the products with the name : apple and the path is /products/apple so the rank of the parameter apple is 1 in this path, so the query will be as following

query={name:%1}
  • Result : As a result of this request we are going to delete all the products with the name apple.

In this example we are going to show how to delete a product using postman as a tool delete-exemple

  • URL : You are going to need the runtime url then you have to add the path which going to be in most cases the collection name and the values of the path variables that we are passing for example : https://app.grizzly-api.com/runtime/5f87ed592e4bc80001219820/products/apple/fruits. in this example considering we have a microservice called Products we assumed that you are going to delete the products with the name apple and the type fruit so we added /products/apple/fruit to the runtime url.
  • Query : we always add the query to the header of our request and it respects the following pattern:
{$operator:[{<attribute_name_1>:%<rank_of_attribute_1_inPath>},{<attribute_name_2>:%<rank_of_attribute_2_inPath>}]}

Here we are deleting the products with the name : apple and type : fruit and the path is /products/apple/fruit so the rank of the parameter apple is the first in this path and fruit is the second and the operator is $and so the query will be as following :

query={$and:[{name:%1},{type:%2}]}
  • Result : As a result of this request we are going to delete all the products with the name apple and type fruits
  • Operators :The supported operators are : $and , $or
  • URL : You are going to need the runtime url then you have to add the path which going to be in most cases the collection name and the value of the path variable that we are passing for example : https://app.grizzly-api.com/runtime/5f87ed592e4bc80001219820/products/1000. in this example considering we have a microservice called Products we assumed that you are going to delete the products which prices are greater than 1000 so we added /products/1000 to the runtime url.
  • Query : we always add the query to the header of our request and it respects the following pattern :
 {<attribute_name>:{$operator:%<rank_of_attribute_inPath>}} 

in this example we are deleting the products which prices are greater than : 1000 and the path is /products/1000 so the rank of the parameter 1000 is the first in the path so the query will be as following

query={price:{$gt:%1}}
  • Result : As a result of this request we are going to delete all the products which prices are higher than 1000
  • Operators :The supported operators for comparasion are $gt for greater than, $lt for less than , $gte for greater or equal , $lte for less or equal