Navigation

Javascript

Overview

Javascript client for bannerify

Get started with our JavaScript SDK, bannerify-js, for a more typed and efficient experience. This SDK allows you to interact with our API without having to make HTTP requests directly.

Install

Instantiate

If you want to use SDK, you will need your api key — you can create a new one in the settings. Afterwards you need to provide it to the client:

import { Bannerify } from "bannerify-js";

const bannerify = new Bannerify('your-api-key');

Response format

Because forgetting to handle thrown errors properly in javascript is often forgotten, we have decided to explicitely return errors to be handled. Fortunately typescript helps us here and everything is typesafe.

Every method returns either an error or a result field, never both and never none.

{
  result: T // the result depends on what method you called
}
{
  error: {
  // A machine readable error code
  code: ErrorCode;

  // A link to our documentation explaining this error in more detail
  docs: string;

  // A human readable short explanation
  message: string;

  // The request id for easy support lookup
  requestId: string;
}
}

Checking for errors

To check for errors you use the error property, our errors are easy to read and provide a link to our documentation for more information.

import { Bannerify } from "bannerify-js";

const bannerify = new Bannerify('your-api-key');
const { result, error } = await bannerify.generateImageSignedUrl('your-template-id');

if (error) {
  // handle potential network or bad request error
  // a link to our docs will be in the `error.docs` field
  console.error(error.message);
  return;
}

// process request
console.log(result);

Options

The constructor accepts some options to customize the behavior:

API key

#apiKeystringrequired

Your project’s API key

const bannerify = new Bannerify('my-api-key')

Timeout

The timeout for the requests in milliseconds, by default it is 10000ms.

const bannerify = new Bannerify('my-api-key',{
  // ...
  timeout: 10000
})

Fetch

The fetch client to use, by default it uses the global fetch client.

const bannerify = new Bannerify('my-api-key',{
  // ...
  fetch: myFetchClient
})