@donation-alerts/api-call
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

Donation Alerts - Api Call

A basic Donation Alerts API call wrapper.

This package contains simple utils that allow you to send requests to different Donation Alerts API endpoints with given credentials.

If you need to use the Donation Alerts API, consider using the @donation-alerts/api package, which allows for more flexibility and convenience in requesting data from the Donation Alerts API. The @donation-alerts/api package already uses this package internally, so you don't need to install it separately.

But if you still need it:

Installation

Using npm:

npm i @donation-alerts/api-call

Using yarn:

yarn add @donation-alerts/api-call

Usage

You can call Donation Alerts API in one of two ways:

  1. Using callDonationAlertsApiRaw() function to get native Response object.
  2. Using callDonationAlertsApi<T>() function to get only payload data. You can specify data type in the type parameter T.

The both functions accepts the same arguments:

You can do the following to request raw data, for example, from alerts/donations endpoint:

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

// Assuming we are inside an async funcation or with top level `await` enabled.
const response = await callDonationAlertsApiRaw(
	{
		url: 'alerts/donations'
	},
	'<YOUR_ACCESS_TOKEN>'
);

The response will be native Response object of the Fetch API.

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

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

// Create an interface that represents the data you expect to receive.
interface PayloadData {
	// ...
}

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

The response will be mapped to the PayloadData interface that we passed as a type parameter.

The function above can throw the HttpError which you can catch and use.


For more information check the documentation.

Package Sidebar

Install

npm i @donation-alerts/api-call

Weekly Downloads

3

Version

3.0.1

License

MIT

Unpacked Size

21.1 kB

Total Files

21

Last publish

Collaborators

  • stimulcross