Compass Docs
  • Collections
    • ๐Ÿš€Trending
    • ๐ŸŒฑMinting Now
    • ๐Ÿ“ƒCollection Watchlists
    • ๐Ÿ–ผ๏ธToken Window
    • โ†”๏ธCollection Activity
    • ๐Ÿ†Collection Profit Leaderboard
    • ๐ŸŽจCollection Tokens
    • ๐Ÿ‹Collection Top Holders
    • โ›๏ธCollection Mint History
    • ๐Ÿ”Collection Analytics
  • Wallets
    • ๐Ÿš€Getting started with Wallets
    • ๐Ÿ‘›Wallet overview
    • ๐Ÿ”Wallet Activity with Filtering
    • ๐Ÿ™‹Own Wallets
    • ๐ŸฅžFlips
    • ๐Ÿ‘ฅWallet Groups
    • ๐Ÿ”—Related Wallets
  • Pulse
    • ๐Ÿฅ‡Profit leaderboard
    • ๐Ÿ“ˆCompass Pulse
  • Alerts
    • โฐGetting Started with Alerts
  • Automations
    • ๐Ÿš€Getting Started with Automations
    • ๐Ÿ’ฐWallets
    • ๐Ÿ“˜Key Terms in Automations
    • ๐Ÿ”€Inputs/Outputs
    • ๐ŸงชTesting Automations
    • ๐Ÿš€Set Up Your First Listing Alert
    • ๐Ÿ”ซTriggers
      • Token Received
      • Token Sent
      • Token Bought
      • Token Sold
      • Token Minted
      • Webhook
      • Repeat
      • Token Listed
      • Telegram
      • Trigger Advanced Settings
    • ๐Ÿ’ณPricing
    • โšกCustom Actions
      • @compass/http
      • @compass/api
      • @compass/cache
      • @compass/utils
      • @compass/variables
      • @compass/wallet
Powered by GitBook
On this page
  • Usage
  • API Reference
  • Examples
  1. Automations
  2. Custom Actions

@compass/http

This package provides simplified HTTP request functionalities, allowing you to make requests using different methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS).

Usage

Import it in the action:

import http from "@compass/http";

API Reference

http.get(url: string, options?: RequestConfig)

Sends a GET request to the specified URL.

  • url (required, string): The URL where the request should be sent.

  • options (optional, RequestConfig): The request configuration options.

Returns a Promise that resolves with the response.

http.post(url: string, data?: any, options?: RequestConfig)

Sends a POST request to the specified URL.

  • url (required, string): The URL where the request should be sent.

  • data (optional, any): The data to be sent as the request body.

  • options (optional, RequestConfig): The request configuration options.

Returns a Promise that resolves with the response. RequestConfig

An object that configures the request. It accepts the following properties:

  • url (optional, string): The URL where the request should be sent.

  • method (optional, 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS'): The HTTP method for the request.

  • headers (optional, object): Any headers you want to add to your request.

  • params (optional, any): URL parameters to be sent with the request.

  • data (optional, any): The data to be sent as the request body. Used primarily with 'POST', 'PUT' and 'PATCH' requests.

Examples

To send a GET request:

import http from "@compass/http";

export default async function() {
    try {
        const data = await http.get('https://example.com/api/items');
        log(data);

        return {
            items: data,
        }
    } catch (error) {
        log(error);
    }
}

To send a POST request:

import http from "@compass/http";

export default async function() {
    const postData = {
        name: 'John',
        email: 'john@example.com'
    };

    try {
        const data = await http.post('https://example.com/api/users', postData);
        log(data);

        return {
            user: data,
        }
    } catch (error) {
        log(error);
    }
}

Remember that error handling is important to take care of any potential errors that might occur during the request.

PreviousCustom ActionsNext@compass/api

Last updated 1 year ago

โšก