Install the SDK
Install the Bunny Node.js or Ruby SDK and configure it with an access token or client credentials to call the Bunny API.
Bunny provides server side libraries that abstract much of the authentication, authorization and request formation boilerplate code required to make API requests.
You can find the source code for the two SDKs here:
Installing the SDKs is straighforward.
Install the Bunny SDK via NPM
npm install @bunnyapp/api-client --save
Set the access token
const Bunny = require("bunny");
const bunny = new Bunny({
accessToken: "<access-token>",
baseUrl: "https://<subdomain>.bunny.com"
});
Or alternatively use client credentials. This will enable automatic refresh of expired access tokens.
const Bunny = require("bunny");
const bunny = new Bunny({
clientId: "<bunny-client-id>",
clientSecret: "<bunny-client-secret>",
scope: "standard:read standard:write",
baseUrl: "https://<subdomain>.bunny.com"
});
Install the Bunny SDK via RubyGems
gem install bunnyapp
Use Rails generator to create initializers/bunny_app.rb
bin/rails g bunny_app:install
Set access token
require 'bunny_app'
BunnyApp.config do |c|
c.access_token = 'xxx'
c.base_uri = 'https://<subdomain>.bunny.com'
end
Or alternatively use client credentials. This will enable automatic refresh of expired access tokens.
require 'bunny_app'
BunnyApp.config do |c|
c.client_id = 'xxx'
c.client_secret = 'xxx'
c.scope = 'standard:read standard:write'
c.base_uri = 'https://<subdomain>.bunny.com'
end
We recommend using one of our official SDKs, however if you want to write your own code then you will need to generate an access token and include it in the Authorization header of your GraphQL requests. You should also keep in mind handling access token expiry errors and retries.