Mirra
Developer Resources

Resource Examples

Resources are API integrations that developers can create, publish, and monetize on the marketplace. These examples demonstrate how to build resources for different use cases, from simple REST APIs to complex OAuth2 integrations and webhook receivers.

Each example shows the complete resource definition, authentication setup, and usage patterns in scripts.

Examples

Creating a cryptocurrency price API

This example demonstrates how to create a REST API resource that provides real-time cryptocurrency price data. The resource defines two methods: one for fetching a single price and another for batch price queries.

API Definition

Create the resource using the POST /api/sdk/v1/resources endpoint:

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 price data",
    "resourceType": "api_endpoint",
    "endpoint": {
      "baseUrl": "https://api.example.com/v1",
      "authentication": "api_key",
      "methods": [
        {
          "name": "getPrice",
          "path": "/prices/{symbol}",
          "method": "GET",
          "parameters": [
            {
              "name": "symbol",
              "type": "string",
              "required": true,
              "description": "Cryptocurrency symbol (e.g., BTC, ETH)"
            }
          ]
        },
        {
          "name": "getPrices",
          "path": "/prices",
          "method": "GET",
          "parameters": [
            {
              "name": "symbols",
              "type": "string[]",
              "required": true,
              "description": "Array of cryptocurrency symbols"
            }
          ]
        }
      ]
    }
  }'

Result

The resource becomes available in the marketplace. Users can install it and call the defined methods from their scripts. This pattern works for any REST API that uses API key authentication.

Building a weather data integration

This example shows how to create a data source resource for weather information. The resource wraps a third-party weather API and exposes a simplified interface for retrieving current weather conditions.

API Definition

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": "data_source",
    "endpoint": {
      "baseUrl": "https://api.weather.com/v3",
      "authentication": "api_key",
      "methods": [
        {
          "name": "getCurrentWeather",
          "path": "/weather/current",
          "method": "GET",
          "parameters": [
            {
              "name": "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.

Setting up a webhook receiver

This example demonstrates how to create a webhook resource that receives event notifications from external services. Webhook resources are useful for integrating with payment processors, CRM systems, and other services that push data to your application.

Webhook Configuration

curl -X POST https://api.fxn.world/api/sdk/v1/resources \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Payment Webhook",
    "description": "Receive payment notifications",
    "resourceType": "webhook",
    "endpoint": {
      "callbackUrl": "https://webhook.example.com/events",
      "events": ["payment.completed", "payment.failed"],
      "authentication": "signature",
      "signatureHeader": "X-Webhook-Signature"
    }
  }'

Result

The webhook resource listens for incoming events and triggers your scripts when events arrive. The platform handles signature verification and event routing automatically.

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 and Monetization

Publishing to the marketplace

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