Module api-call - v4.0.0

Donation Alerts - Api Call

A lightweight wrapper for making API calls to Donation Alerts.

This package provides simple utilities for sending requests to various Donation Alerts API endpoints using provided credentials. Although it is mainly intended for internal use, some of its utilities may prove useful in your own code. For a more flexible and feature-rich experience with the Donation Alerts API, consider using the @donation-alerts/api package.

npm i @donation-alerts/api-call
yarn add @donation-alerts/api-call
pnpm add @donation-alerts/api-call

You can call the Donation Alerts API in two ways:

  1. Using callDonationAlertsApiRaw(): This function returns the native Response object from the Fetch API.

  2. Using callDonationAlertsApi<T>(): This function returns only the payload data, which you can type via the generic parameter T.

Both functions accept the following arguments:

To fetch raw data from the alerts/donations endpoint:

import { callDonationAlertsApiRaw } from '@donation-alerts/api-call';

// Within an async function or when using top-level await:
const response = await callDonationAlertsApiRaw(
{
url: 'alerts/donations',
},
'<YOUR_ACCESS_TOKEN>',
);

// 'response' is the native Response object from the Fetch API.

To receive only the mapped payload data, you can do the following:

import { callDonationAlertsApi } from '@donation-alerts/api-call';

// Define an interface representing the expected payload.
interface PayloadData {
// ...
}

const response = await callDonationAlertsApi<PayloadData>(
{
url: '<endpoint>',
},
'<YOUR_ACCESS_TOKEN>',
);

// 'response' is mapped to the PayloadData interface.
Note

The above function may throw an HttpError, which you should catch and handle accordingly.


For more detailed information, please refer to the documentation.

Classes

HttpError

Interfaces

DonationAlertsApiCallOptions

Type Aliases

DonationAlertsCallFetchOptions
DonationAlertsCallType

Functions

callDonationAlertsApi
callDonationAlertsApiRaw