Page cover

REST and WebSocket API

1.1 REST API Overview

The REST API endpoints follow standard HTTP methods and return JSON responses. The following examples cover essential endpoints for asset management, NFT operations, and data retrieval.


1.2 Authentication

All requests to protected endpoints require an API key and authentication token. Requests must include the token in the Authorization header, formatted as:

Authorization: Bearer <token>

1.3 Main REST API Endpoints

Endpoint
Method
Description

/api/v1/auth/login

POST

Authenticates the user and provides a token.

/api/v1/nft/create

POST

Creates a new NFT asset.

/api/v1/assets

GET

Retrieves a list of all assets.

/api/v1/price/:id

GET

Gets current price data for a specific asset.

/api/v1/transfer

POST

Initiates a transfer of assets.

1.3.1 Authentication: Login Endpoint

Endpoint: /api/v1/auth/login Method: POST Description: Authenticates the user and returns an access token for use with other API requests.

Parameters:

  • username (string, required): User’s username.

  • password (string, required): User’s password.

Sample Request (cURL):

curl -X POST "https://api.capsurelabs.com/api/v1/auth/login" \
  -H "Content-Type: application/json" \
  -d '{"username": "user@example.com", "password": "examplePassword"}'

Sample Response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "expiresIn": 3600
}

1.3.2 NFT Creation

Endpoint: /api/v1/nft/create Method: POST Description: Creates a new NFT with the specified metadata.

Parameters:

  • name (string, required): The name of the NFT.

  • description (string, optional): A description of the NFT.

  • metadata (object, required): Metadata including the NFT image URL, attributes, and creator information.

Sample Request (Postman):

  • Select POST method.

  • Set the URL to https://api.capsurelabs.com/api/v1/nft/create.

  • In the Authorization tab, add a Bearer Token (Authorization: Bearer <token>).

  • In the Body tab, select raw and set the Content-Type to JSON.

{
  "name": "CapsureLabs NFT",
  "description": "A unique digital asset from CapsureLabs.",
  "metadata": {
    "image": "https://cdn.capsurelabs.com/nft-images/unique-nft.png",
    "attributes": [
      { "trait_type": "Background", "value": "Blue" },
      { "trait_type": "Edition", "value": "Genesis" }
    ]
  }
}

Sample Response:

{
  "success": true,
  "nftId": "0x123abc456def",
  "message": "NFT created successfully."
}

1.3.3 Asset List Retrieval

Endpoint: /api/v1/assets Method: GET Description: Retrieves a list of all assets available to the authenticated user.

Sample Request (cURL):

curl -X GET "https://api.capsurelabs.com/api/v1/assets" \
  -H "Authorization: Bearer <token>"

Sample Response:

[
  {
    "assetId": "0x123abc",
    "name": "Ethereum",
    "type": "Cryptocurrency",
    "balance": 2.5
  },
  {
    "assetId": "0x456def",
    "name": "CapsureLabs NFT",
    "type": "NFT",
    "metadata": {
      "image": "https://cdn.capsurelabs.com/nft-images/unique-nft.png",
      "attributes": [
        { "trait_type": "Background", "value": "Blue" },
        { "trait_type": "Edition", "value": "Genesis" }
      ]
    }
  }
]

1.3.4 Asset Price Retrieval

Endpoint: /api/v1/price/:id Method: GET Description: Gets the current price of the specified asset by id.

Parameters:

id (string, required): The unique identifier of the asset (e.g., Ethereum or NFT ID).

Sample Request (cURL):

curl -X GET "https://api.capsurelabs.com/api/v1/price/ethereum" \
  -H "Authorization: Bearer <token>"

Sample Response:

{
  "assetId": "ethereum",
  "priceUSD": 3500.75,
  "priceChange24h": 2.1
}

1.4 WebSocket API Overview

The WebSocket API provides real-time event data for CapsureLabs' users, including price updates and asset transfers.

WebSocket Endpoint: wss://api.capsurelabs.com/ws

1.4.1 Supported Events

  • priceUpdate: Sends price updates in real-time for subscribed assets.

  • newTransfer: Notifies users when a new transfer involving their assets occurs.

  • newNFT: Informs users of new NFT minting events.

WebSocket Connection and Subscription

The following code example shows how to connect to CapsureLabs’ WebSocket API and subscribe to priceUpdate events.

JavaScript WebSocket Code:

const WebSocket = require('ws');
const ws = new WebSocket("wss://api.capsurelabs.com/ws");

// Event listener for WebSocket connection
ws.on("open", () => {
    console.log("Connected to WebSocket server");

    // Subscribe to price updates for Ethereum
    ws.send(JSON.stringify({
        event: "subscribe",
        channel: "priceUpdate",
        asset: "ethereum"
    }));
});

// Handle incoming messages
ws.on("message", (data) => {
    const message = JSON.parse(data);
    if (message.event === "priceUpdate") {
        console.log(`New price for Ethereum: ${message.priceUSD} USD`);
    }
});

Sample WebSocket Message for priceUpdate Event:

{
  "event": "priceUpdate",
  "asset": "ethereum",
  "priceUSD": 3510.25,
  "priceChange24h": 1.8
}

Last updated