TypeScript

SDK for bunny.net 🐰

NPM Version

Installation

npm install bunny-sdk

Prerequisites

  • Please read the authentication guide to learn more about where to find your AccessKey and which AccessKey should be used for each client.
  • Please read the limitations guide to learn more about known limitations and bugs, such as nullable and optional typing.
  • Please read the supported endpoints guide to learn more about which endpoints are supported.

Quickstart

Create the client

import { createBunnyApiClient } from 'bunny-sdk'const bunnyApiClient = createBunnyApiClient({  accessKey: process.env.BUNNY_ACCESS_KEY!,})

Call a simple endpoint

fetch countries

import { createBunnyApiClient } from 'bunny-sdk'const bunnyApiClient = createBunnyApiClient({  accessKey: process.env.BUNNY_ACCESS_KEY!,})const countries = await bunnyApiClient.country.get() 

log countries

import { createBunnyApiClient } from 'bunny-sdk'const bunnyApiClient = createBunnyApiClient({  accessKey: process.env.BUNNY_ACCESS_KEY!,})const countries = await bunnyApiClient.country.get()countries?.forEach((country, index) => {  console.log(`${index}: ${country.name}`)})

Call a complex endpoint

The List Storage Zones endpoint is a more complex example that has required parameters.

fetch storage zones

import { createBunnyApiClient } from 'bunny-sdk'const bunnyApiClient = createBunnyApiClient({  accessKey: process.env.BUNNY_ACCESS_KEY!,})const storageZones = await bunnyApiClient.storagezone.get({  queryParameters: {    includeDeleted: true,    page: 1,    perPage: 1000,  },})

log storage zones

import { createBunnyApiClient } from 'bunny-sdk'const bunnyApiClient = createBunnyApiClient({  accessKey: process.env.BUNNY_ACCESS_KEY!,})const storageZones = await bunnyApiClient.storagezone.get({  queryParameters: {    includeDeleted: true,    page: 1,    perPage: 1000,  },})storageZones?.items?.forEach((storageZone, index) => {  console.log(`${index}: ${storageZone.name}`)})

All required parameters from the documentation are also required in the Bunny SDK. In this example, the required parameters are:

  • includeDeleted
  • page
  • perPage

Despite the documentation setting the default page parameter to 0, the default value fails the validation, where the minimum page is 1.

If you receive a 400 Bad Request error, please double-check your parameters.

TypeScript types

Most model and enum types are found in:

  • bunny-sdk/<client>/models/<group>.
  • bunny-sdk/<client>/<group>
import type {  StorageZone,  EdgeReplicationRegions,} from 'bunny-sdk/bunnyApiClient/models/storageZone'