We will use the Truebit CLI to and the API Task. Once it's ready, we will deploy it to the coordination hub so that everyone who knows the namespace
and taskname
.
Step 1. Define the API Manifest
The manifest is already defined within the folder "examples/api-tasks/petstore-crud/manifest.json"".
Step 2. Test the API Task
Execute the command to test the manifest.
Add a new record using the POST Verb
Copy truebit start-api truebit-nextgen-examples/api-tasks/petstore-crud/manifest.json truebit-nextgen-examples/api-tasks/petstore-crud/post.add.input.json
Output
Copy Executing the API Task
API Task executed with status - OK
Input request :
{
"path": "/store/order",
"method": "POST",
"body": {
"id": 2,
"petId": 198772,
"quantity": 7,
"shipDate": "2077-08-24T14:15:22Z",
"status": "approved",
"complete": true
},
"headers": {}
}
Base URL = https://petstore.swagger.io/v2
OpenAPI manifest check - OK
API Task response
{
"id": 2,
"petId": 198772,
"quantity": 7,
"shipDate": "2077-08-24T14:15:22.000+0000",
"status": "approved",
"complete": true
}
Retrieve the record using the GET Verb
Copy truebit start-api truebit-nextgen-examples/api-tasks/petstore-crud/manifest.json truebit-nextgen-examples/api-tasks/petstore-crud/get.input.json
Output
Copy Executing the API Task
API Task executed with status - OK
Input request :
{
"path": "/store/order/{orderId}",
"method": "GET",
"params": {
"orderId": 2
},
"headers": {}
}
Base URL = https://petstore.swagger.io/v2
OpenAPI manifest check - OK
API Task response
{
"id": 2,
"petId": 198772,
"quantity": 7,
"shipDate": "2077-08-24T14:15:22.000+0000",
"status": "approved",
"complete": true
}
Update the record using the POST Verb
Copy truebit start-api truebit-nextgen-examples/api-tasks/petstore-crud/manifest.json truebit-nextgen-examples/api-tasks/petstore-crud/post.update.input.json
Output
Copy Executing the API Task
API Task executed with status - OK
Input request :
{
"path": "/store/order",
"method": "POST",
"body": {
"id": 2,
"petId": 198772,
"quantity": 18,
"shipDate": "2077-08-24T14:15:22Z",
"status": "approved",
"complete": true
},
"headers": {}
}
Base URL = https://petstore.swagger.io/v2
OpenAPI manifest check - OK
API Task response
{
"id": 2,
"petId": 198772,
"quantity": 18,
"shipDate": "2077-08-24T14:15:22.000+0000",
"status": "approved",
"complete": true
}
Delete the record using the DELETE Verb
Copy truebit start-api truebit-nextgen-examples/api-tasks/petstore-crud/manifest.json truebit-nextgen-examples/api-tasks/petstore-crud/delete.input.json
Output
Copy Executing the API Task
API Task executed with status - OK
Input request :
{
"path": "/store/order/{orderId}",
"method": "DELETE",
"params": {
"orderId": 2
},
"headers": {}
}
Base URL = https://petstore.swagger.io/v2
OpenAPI manifest check - OK
API Task response
{
"code": 200,
"type": "unknown",
"message": "2"
}
Step 3. Create the API Task
Copy truebit create-api truebit-nextgen-examples/api-tasks/petstore-crud/manifest.json
Output
Copy Creating API task...
OpenAPI manifest is valid!
Your API task is ready!
Use the following TaskId for execution or deployment:
api_31708510ced0a56232267d4575064026180118e52c7e9236f366202e14934bd5/1.0.0
Step 4. Deploy the API Task
Copy truebit deploy <namespace> <taskname> --taskId api_31708510ced0a56232267d4575064026180118e52c7e9236f366202e14934bd5/1.0.0
Output
Copy Deploying the API task
The function task has been deployed successfully.