Mirra
Mirra APIResources

Resource Examples

Resources enable you to create, publish, and monetize API integrations on the marketplace. These examples demonstrate how to build resources for different use cases, from simple REST APIs to complex OAuth2 integrations.

Creating an API Resource

This example creates a cryptocurrency price API resource with API key authentication and pay-per-call pricing.

Request

curl -X POST https://api.fxn.world/api/sdk/v1/resources \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Crypto Price API",
    "description": "Real-time cryptocurrency prices",
    "resourceType": "api",
    "category": "crypto",
    "tags": ["crypto", "prices", "trading"],
    "openApiSpec": {
      "openapi": "3.0.0",
      "info": {
        "title": "Crypto Price API",
        "version": "1.0.0"
      },
      "servers": [{"url": "https://api.crypto-prices.com"}],
      "paths": {
        "/v1/price/{symbol}": {
          "get": {
            "summary": "Get cryptocurrency price",
            "parameters": [
              {
                "name": "symbol",
                "in": "path",
                "required": true,
                "schema": {"type": "string"}
              }
            ],
            "responses": {
              "200": {
                "description": "Price data",
                "content": {
                  "application/json": {
                    "schema": {
                      "type": "object",
                      "properties": {
                        "price": {"type": "number"},
                        "symbol": {"type": "string"}
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "endpoint": {
      "baseUrl": "https://api.crypto-prices.com",
      "authentication": "api_key",
      "methods": [
        {
          "name": "getPrice",
          "httpMethod": "GET",
          "path": "/v1/price/{symbol}",
          "description": "Get current price for a cryptocurrency",
          "parameters": {
            "symbol": {
              "type": "string",
              "required": true
            }
          },
          "response": {
            "type": "object"
          }
        }
      ]
    },
    "pricing": {
      "model": "pay-per-call",
      "basePrice": 0.001,
      "currency": "USDC"
    }
  }'

Response

{
  "success": true,
  "data": {
    "id": "resource_abc123",
    "name": "Crypto Price API",
    "resourceType": "api",
    "status": "draft",
    "createdAt": "2025-11-15T12:00:00Z"
  }
}

The resource is created in draft status and must be published before it appears in the marketplace.


Creating an LLM Resource

This example creates an OpenAI GPT-4 resource with bearer token authentication for chat completion.

Request

curl -X POST https://api.fxn.world/api/sdk/v1/resources \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "GPT-4 Chat",
    "description": "OpenAI GPT-4 chat completion endpoint",
    "resourceType": "llm",
    "category": "ai",
    "tags": ["llm", "chat", "openai"],
    "openApiSpec": {
      "openapi": "3.0.0",
      "info": {
        "title": "OpenAI Chat API",
        "version": "1.0.0"
      },
      "servers": [{"url": "https://api.openai.com/v1"}],
      "paths": {
        "/chat/completions": {
          "post": {
            "summary": "Create chat completion",
            "requestBody": {
              "required": true,
              "content": {
                "application/json": {
                  "schema": {
                    "type": "object",
                    "properties": {
                      "model": {"type": "string"},
                      "messages": {"type": "array"}
                    }
                  }
                }
              }
            },
            "responses": {
              "200": {
                "description": "Chat completion response"
              }
            }
          }
        }
      }
    },
    "endpoint": {
      "baseUrl": "https://api.openai.com/v1",
      "authentication": "bearer",
      "methods": [
        {
          "name": "chatCompletion",
          "httpMethod": "POST",
          "path": "/chat/completions",
          "description": "Generate chat completion",
          "parameters": {
            "model": {"type": "string", "required": true},
            "messages": {"type": "array", "required": true}
          },
          "response": {"type": "object"},
          "cost": 0.002
        }
      ]
    },
    "pricing": {
      "model": "pay-per-call",
      "basePrice": 0.002,
      "currency": "USDC"
    }
  }'

To create a chat UI with subdomain deployment (e.g., mychat.username.getmirra.app), bundle your LLM resource in a Template.


Weather Data Integration

This example shows how to create a data source resource for weather information with a simplified interface.

Request

curl -X POST https://api.fxn.world/api/sdk/v1/resources \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Weather API",
    "description": "Current weather and forecasts",
    "resourceType": "api",
    "category": "data",
    "endpoint": {
      "baseUrl": "https://api.weather.com/v3",
      "authentication": "api_key",
      "methods": [
        {
          "name": "getCurrentWeather",
          "httpMethod": "GET",
          "path": "/weather/current",
          "parameters": {
            "location": {
              "type": "string",
              "required": true,
              "description": "City name or coordinates"
            }
          }
        }
      ]
    }
  }'

Result

The resource provides a clean interface for weather data. Users authenticate once with their weather API key, then call methods without managing authentication in their scripts.


Installing and Using Resources

Installing a Resource

Users install resources before using them in scripts:

curl -X POST https://api.fxn.world/api/sdk/v1/resources/RESOURCE_ID/install \
  -H "Authorization: Bearer YOUR_API_KEY"

Installation creates a personal instance of the resource for the user. Each user maintains their own authentication credentials and usage metrics.

Authenticating with API Keys

Set up API key authentication for installed resources:

curl -X POST https://api.fxn.world/api/sdk/v1/resources/RESOURCE_ID/authenticate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "api_key",
    "credentials": {
      "apiKey": "your-api-key"
    }
  }'

The platform stores credentials securely and injects them automatically when scripts call resource methods.

Authenticating with OAuth2

For OAuth2-enabled resources, provide client credentials:

curl -X POST https://api.fxn.world/api/sdk/v1/resources/RESOURCE_ID/authenticate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "oauth2",
    "credentials": {
      "clientId": "your-client-id",
      "clientSecret": "your-client-secret"
    }
  }'

The platform handles the OAuth2 flow, including token refresh, automatically. Scripts access resources without managing tokens.

Using Resources in Scripts

Access installed resources through the global resources object:

export async function handler(event) {
  // Call the getPrice method on the installed resource
  const price = await resources['crypto-price-api'].getPrice({
    symbol: 'BTC'
  });
  
  return { 
    symbol: 'BTC',
    price: price.current,
    timestamp: new Date().toISOString()
  };
}

The resource name in the resources object matches the resource's identifier. All authentication and error handling happens automatically.


Publishing to Marketplace

Publishing a Resource

Make your resource available to other users:

curl -X POST https://api.fxn.world/api/sdk/v1/resources/RESOURCE_ID/publish \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "pricing": {
      "model": "pay-per-use",
      "basePrice": 0.001,
      "currency": "USDC"
    },
    "category": "crypto",
    "tags": ["cryptocurrency", "prices", "market-data"]
  }'

Published resources appear in the marketplace. You earn revenue each time users call your resource's methods.

Browsing the Marketplace

Find available resources by category:

curl "https://api.fxn.world/api/sdk/v1/resources/marketplace?category=crypto" \
  -H "Authorization: Bearer YOUR_API_KEY"

The response includes resource metadata, pricing information, and installation counts. Filter by category, tags, or search terms to find relevant integrations.

Monitoring Resource Usage

Track usage metrics and revenue for your published resources:

curl https://api.fxn.world/api/sdk/v1/resources/RESOURCE_ID/metrics \
  -H "Authorization: Bearer YOUR_API_KEY"

Metrics include total calls, unique users, revenue earned, and error rates. Use this data to optimize pricing and improve resource reliability.


Best Practices

API Design Guidelines

Design resources that are easy to use and maintain:

Do:

  • Use clear, descriptive method names (getPrice, not fetch)
  • Document all parameters with types and descriptions
  • Include response schema documentation
  • Handle errors gracefully with meaningful messages
  • Version your API to allow non-breaking updates

Avoid:

  • Unclear parameter names (data, info, obj)
  • Missing or incomplete documentation
  • Inconsistent response formats across methods
  • Breaking changes without version updates
  • Exposing internal implementation details

Authentication Patterns

Support standard authentication methods:

  • API Key: Simple and widely supported—use for most REST APIs
  • OAuth2: Required for services that need user authorization
  • Webhook Signatures: Verify webhook authenticity using HMAC signatures
  • Bearer Tokens: For APIs that use JWT or similar token schemes

Always store credentials securely. Never log or expose credentials in error messages or responses.

Pricing Strategies

Choose a pricing model that matches your resource's value:

  • Free: Good for open data sources or promotional resources
  • Pay-per-use: Charge per API call (e.g., $0.001 per request)
  • Subscription: Fixed monthly fee for unlimited usage
  • Tiered: Combine free tier with paid tiers for high-volume users

Consider your costs when setting prices. Include API provider fees, infrastructure costs, and support overhead.

Error Handling

Implement robust error handling in your resource:

// Resource wrapper example
async function getPrice(symbol) {
  try {
    const response = await fetch(`${baseUrl}/prices/${symbol}`, {
      headers: { 'Authorization': `Bearer ${apiKey}` }
    });
    
    if (!response.ok) {
      throw new Error(`API error: ${response.status}`);
    }
    
    return await response.json();
  } catch (error) {
    // Log error for monitoring
    console.error('Price fetch failed:', error);
    throw new Error(`Failed to fetch price for ${symbol}`);
  }
}

Return clear error messages that help users debug issues without exposing sensitive information.


See Also

On this page