Pet Store CRUD
We will use the Truebit CLI to Create and Test 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 start-api command to test the manifest.
Add a new record using the POST Verb
truebit start-api truebit-nextgen-examples/api-tasks/petstore-crud/manifest.json truebit-nextgen-examples/api-tasks/petstore-crud/post.add.input.json
Output
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
truebit start-api truebit-nextgen-examples/api-tasks/petstore-crud/manifest.json truebit-nextgen-examples/api-tasks/petstore-crud/get.input.json
Output
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
truebit start-api truebit-nextgen-examples/api-tasks/petstore-crud/manifest.json truebit-nextgen-examples/api-tasks/petstore-crud/post.update.input.json
Output
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
truebit start-api truebit-nextgen-examples/api-tasks/petstore-crud/manifest.json truebit-nextgen-examples/api-tasks/petstore-crud/delete.input.json
Output
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
Execute the create-api command against the Truebit Verify Node to execute the endpoint.
truebit create-api truebit-nextgen-examples/api-tasks/petstore-crud/manifest.json
Output
Creating API task...
OpenAPI manifest is valid!
Your API task is ready!
Use the following TaskId for execution or deployment:
api_31708510ced0a56232267d4575064026180118e52c7e9236f366202e14934bd5
Step 4. Deploy the API Task
Last but not least, please go ahead and execute the deploy command to deploy the API task to the coordination hub, so that anyone with the taskId can use it.
truebit deploy <namespace> <taskname> --taskId api_31708510ced0a56232267d4575064026180118e52c7e9236f366202e14934bd5
Output
Deploying the API task
The function task has been deployed successfully.
Last updated
Was this helpful?