Building the services
Objectives
Get more familiar with the built in Swagger Editor to build a service
Get more familiar with writing BL based on the composer
To create any service, you need to write your APIs, your service configuration and finally each API business logic based on your needs.
Go to the Develop pillar → Swagger Editor → Swagger Documentation Tab
Write your APIs documentation and press run to make sure you don't have any error (you can use http://editor.swagger.io/ to spot errors then copy the code and paste it in the editor). You can find the code here.
AT this stage, your service isn't yet deployed so you can just try your code to make sure that your schema is correct and as intended. Press on an API, enter the values and press on Try it Out!
Press on Service Information tab to fill the configuration
Fill all the fields with the following inputs:
Service Name: petstore
Service Group: petstore
Service Port: 4215
Service Version: 1
Request Timeout: 30
Request Timeout Renewal: 5
extKeyRequired: true
oauth: true
Session: true
Database:
Prefix:
Name: petStore
multitenant: false
model: mongo
Click on Generate Service, a zip file will be downloaded
To learn how to build your service, click here.
This service contains 4 APIs:
Route | Method | Parameters | Description |
|---|---|---|---|
/pets | GET | none | This API lists all the pets available in the store without any condition, by hitting the pets collection to get its entries. |
/pet | POST | pet: {
| This API adds a new pet to the store, by inserting a new entry to the database |
/pet/:id | PUT | pet: {
id: required | This API updates a pet in the store using the mongo id of the record |
/pet/:id | DELETE | id: required | This API deletes a pet from the store using the mongo id record |
As we mentioned in the service information 1.b, extKeyRequired is set to true. So, an external key is required and sent in the headers to check if you are logged in and have access to this API.
You can get the code from here.