Truebit Verify
  • Getting Started
    • 📄What is Truebit Verify?
      • How does Truebit work?
      • System Actors
    • ⏱️Get Started
    • ⚙️Architecture
      • Truebit Verify Hub
      • Truebit Verify Nodes
      • What is a transcript?
        • Transcript example
        • API Transcript example
    • Key Concepts
      • What is verification?
      • Determinism
      • WebAssembly
      • Task instrumentation
  • Developing Truebit Tasks
    • Introduction
    • Writing Function Tasks
      • Supported languages
        • Javascript
        • Python
        • Rust
    • Writing API Tasks
    • Task examples
      • Function Task examples
        • Fibonacci
        • Reverse Alphabet
        • Encrypt sha256 using bun.js
        • Encrypt sha256 using Deno
        • ECDSA signature verification
        • NumPy example
      • API Task examples
        • Pet Store CRUD
        • API-Auth examples
    • Namespace management
    • Task Authorization
    • Truebit CLI
      • secret.json
  • Executing Truebit tasks
    • Introduction
    • Task Execution API
      • Execute Function Tasks
      • Execute API Tasks
      • Get Task Status
    • Transcript API
      • Get Transcript
      • Get Invoice
  • Community
    • Truebit Unchained Protocol
    • Support
Powered by GitBook
On this page
  • Step 1. Define the API Manifest
  • Step 2. Test the API Task
  • Step 3. Create the API Task
  • Step 4. Deploy the API Task

Was this helpful?

  1. Developing Truebit Tasks
  2. Task examples
  3. API Task examples

Pet Store CRUD

PreviousAPI Task examplesNextAPI-Auth examples

Last updated 8 days ago

Was this helpful?

We will use the to and the API Task. Once it's ready, we will 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

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

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

truebit deploy <namespace> <taskname> --taskId api_31708510ced0a56232267d4575064026180118e52c7e9236f366202e14934bd5

Output

Deploying the API task
The function task has been deployed successfully.

Execute the command against the Truebit Verify Node to execute the endpoint.

Last but not least, please go ahead and execute the command to deploy the API task to the coordination hub, so that anyone with the taskId can use it.

Truebit CLI
deploy
Create
Test
start-api
create-api
deploy