Java

SDK for bunny.net 🐰

Maven Central Version

Installation

Add the following dependencies to your build.gradle file:

implementation 'com.bunny-launcher:bunny-sdk:0.0.0'

Replace 0.0.0 with the latest version.

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

package org.example;import bunny.sdk.BunnySdk;import bunny.sdk.CreateBunnyApiClientParameters;import bunny.sdk.bunnyapiclient.BunnyApiClient;public class App {  public static void main(String[] args) {    final BunnyApiClient client = BunnySdk.createBunnyApiClient(      CreateBunnyApiClientParameters.Builder.create()        .setAccessKey(System.getenv().getOrDefault("BUNNY_ACCESS_KEY", ""))        .build()    );  }}

Call a simple endpoint

fetch countries

package org.example;import java.util.List; import bunny.sdk.BunnySdk;import bunny.sdk.CreateBunnyApiClientParameters;import bunny.sdk.bunnyapiclient.BunnyApiClient;import bunny.sdk.bunnyapiclient.models.countries.getcountrylist.Country; public class App {  public static void main(String[] args) {    final BunnyApiClient client = BunnySdk.createBunnyApiClient(      CreateBunnyApiClientParameters.Builder.create()        .setAccessKey(System.getenv().getOrDefault("BUNNY_ACCESS_KEY", ""))        .build()    );    try {      List<Country> countries = client.country()        .get();    } catch (Exception e) {      System.out.println(e.getMessage());      throw e;    }  }}

log countries

package org.example;import java.util.List;import bunny.sdk.BunnySdk;import bunny.sdk.CreateBunnyApiClientParameters;import bunny.sdk.bunnyapiclient.BunnyApiClient;import bunny.sdk.bunnyapiclient.models.countries.getcountrylist.Country;public class App {  public static void main(String[] args) {    final BunnyApiClient client = BunnySdk.createBunnyApiClient(      CreateBunnyApiClientParameters.Builder.create()        .setAccessKey(System.getenv().getOrDefault("BUNNY_ACCESS_KEY", ""))        .build()    );    try {      List<Country> countries = client.country()        .get();      for (int i = 0; i < countries.size(); ++i) {        System.out.printf("%d: %s\n", i, countries.get(i).getName());      }    } catch (Exception e) {      System.out.println(e.getMessage());      throw e;    }  }}

Call a complex endpoint

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

fetch storage zones

package org.example;import java.util.List; import bunny.sdk.BunnySdk;import bunny.sdk.CreateBunnyApiClientParameters;import bunny.sdk.bunnyapiclient.BunnyApiClient;import bunny.sdk.bunnyapiclient.models.storagezone.StorageZone; import bunny.sdk.bunnyapiclient.storagezone.StoragezoneGetResponse; public class App {  public static void main(String[] args) {    final BunnyApiClient client = BunnySdk.createBunnyApiClient(      CreateBunnyApiClientParameters.Builder.create()        .setAccessKey(System.getenv().getOrDefault("BUNNY_ACCESS_KEY", ""))        .build()    );    try {      StoragezoneGetResponse storageZoneGetResponse = client.storagezone()        .get(request -> {          request.queryParameters.includeDeleted = true;          request.queryParameters.page = 1;          request.queryParameters.perPage = 1000;        });      List<StorageZone> storageZones = storageZoneGetResponse.getItems();    } catch (Exception e) {      System.out.println(e.getMessage());      throw e;    }  }}

log storage zones

package org.example;import java.util.List;import bunny.sdk.BunnySdk;import bunny.sdk.CreateBunnyApiClientParameters;import bunny.sdk.bunnyapiclient.BunnyApiClient;import bunny.sdk.bunnyapiclient.models.storagezone.StorageZone;import bunny.sdk.bunnyapiclient.storagezone.StoragezoneGetResponse;public class App {  public static void main(String[] args) {    final BunnyApiClient client = BunnySdk.createBunnyApiClient(      CreateBunnyApiClientParameters.Builder.create()        .setAccessKey(System.getenv().getOrDefault("BUNNY_ACCESS_KEY", ""))        .build()    );    try {      StoragezoneGetResponse storageZoneGetResponse = client.storagezone()        .get(request -> {          request.queryParameters.includeDeleted = true;          request.queryParameters.page = 1;          request.queryParameters.perPage = 1000;        });      List<StorageZone> storageZones = storageZoneGetResponse.getItems();      for (int i = 0; i < storageZones.size(); ++i) {        System.out.printf("%d: %s\n", i, storageZones.get(i).getName());      }    } catch (Exception e) {      System.out.println(e.getMessage());      throw e;    }  }}

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.

Java classes

Most model and enum classes are found in:

  • bunny.sdk.<client>.<group>.<class>;
  • bunny.sdk.<client>.models.<group>.<class>;
import bunny.sdk.bunnyapiclient.storagezone.StoragezoneGetResponse;import bunny.sdk.bunnyapiclient.models.storagezone.StorageZone;