This walkthrough will explain you how to correctly create a microservice to access to a CRUD of riders from the DevOps Console.
In order to do so, access to Mia-Platform DevOps Console. Choose a project or create a new project and navigate to Design area.
Select CRUD on the menu on the left sidebar and now create a new one. Choose from Mia-Platform Marketplace for this walkthrough the following example: Node.js Call CRUD Example. In the compilation form:
- Choose microservices-example as name of this service
- In Git repository owner use the recommended value
- In Git repository name use the name that you will use for your project
- In Docker Image Name use the recommended value contained in the select
then confirm that you want to create a microservice. After this you will be redirected to your new microservice detail page.
A more detailed description on how to create a Microservice can be found in Microservice from template - Get started section of Mia-Platform documentation.
This microservices example requires to set the value of an environment variable to work properly. Go to Environment variable configuration section at the bottom of the page. Add a new field to the table. Inside the popup that will open compile the form with:
- key: CRUD_PATH
- value: {{YOUR CRUD SERVICE PATH}}
More information on how to set an environment variable can be found in Environment Variable Configuration section of Mia-Platform documentation.
In order to access to your new microservice it is necessary to create an endpoint that targets it.
To do so, from the Design area of your project select Endpoints and then create a new endpoint and call it /microservices-endpoint-example.
The type of this endpoint is microservices,
then select the microservice calls microservices-example just created in Create a microservice.
See step 2 of Microservice from template - Get started section of Mia-Platform documentation will explain in detail how to create an endpoint from the DevOps Console.
Now the goal of this example is to call your crud with this service.
Inside of this service we have created some route: GET and POST for /riders
and GET for /riders/:id
.
The next step is create this CRUD of riders so that your microservice can connect to it.
From the Design area of your project select "CRUD" on the menu on the left sidebar.
- Create a new CRUD with the following name: riders then you will be redirected to your CRUD detail page.
- Add some properties to this crud in the Fields section.
In this walkthrough you should add two simple properties: name and surname, both of type String.
A more detailed description on how to create and add properties to a CRUD can be found in CRUD section of Mia-Platform documentation.
Now you need to expose this CRUD with an endpoint. In a similar way to what you have done when creating an endpoint to your microservice, you have to select Endpoints section again.
- Create a new endpoint called /riders.
- Choose type crud
- Select the riders CRUD created in Create a CRUD and select it.
Now you should have two endpoints, one for our CRUD riders and one for our microservice microservices-example If these endpoints are missing we recommend that you review the steps explained above
In design area you can see the commit and generate button.
Click it and commit the changes that you have done in your project.
After some seconds you will be prompted with a popup message which confirms that you have successfully saved all your changes.
See step 3 of Microservice from template - Get started section of Mia-Platform documentation will explain how to correctly save the changes you have made on your project in the DevOps console.
Go to the Deploy area of the DevOps Console.
Here select environment and branch you have worked on and confirm your choices clicking on the deploy button.
When the deploy process is finished you will receive a pop-up message that will inform you have successfully deployed.
See step 4 of Microservice from template - Get started section of Mia-Platform documentation will explain in detail how to correctly deploy your project.
In navigation menu click the documentation sub menu and choose the environment in which you previously released your changes.
Launch the following command on your terminal (remember to replace <YOUR_PROJECT_HOST>
with the real host of your project)
curl <YOUR_PROJECT_HOST>/microservices-endpoint-example/riders
You should see the following message:
[]
Since there are no riders in your CRUD, you received an empty list, but you can launch a POST request on your terminal to change this:
curl --request POST \
--url <YOUR_PROJECT_HOST>/microservices-endpoint-example/riders/ \
--header 'accept: */*' \
--header 'content-type: application/json' \
--data '{"name":"Foo","surname":"Bar","__STATE__":"PUBLIC"}'
After launching this command you should see in your terminal the id (<YOUR_RIDER_ID>) of the rider that you have just inserted in your CRUD. Launch again:
curl <YOUR_PROJECT_HOST>/microservices-endpoint-example/riders
The message that you see should be something like this:
[{"_id": "<YOUR_RIDER_ID>","name":"Foo","surname":"Bar","__STATE__":"PUBLIC", ...}]
Congratulations! You have successfully learnt how to use our Node.js Call CRUD Example on the DevOps Console!