Skip to main content

Serverless

The serverless API implementation is based on Cloudflare Workers and the Serverless Framework. A free Cloudflare Workers account contains 100.000 free requests. So just give it a try.

Installation#

Step 1#

First register on Cloudflare and add a domain to your account.

Step 2#

Checkout our repository avatars-serverless:

git checkout https://github.com/DiceBear/avatars-serverless.git

Step 3#

Change to the project directory and copy the file .env.dist to .env:

cd avatars-serverless
cp .env.dist .env

Step 4#

Edit the new created .env file and enter the following data:

  • CLOUDFLARE_ACCOUNT_ID

    1. Log in to your Cloudflare account and select your domain.
    2. On the right, look for Account ID and click Click to copy below the input.
  • CLOUDFLARE_ZONE_ID

    1. Log in to your Cloudflare account and select your domain.
    2. On the right, look for Zone ID and click Click to copy below the input.
  • CLOUDFLARE_AUTH_KEY

    1. Log in to your Cloudflare account and navigate to My Profile => API Tokens.
    2. On the bottom, look for Global API Key and click View.
    3. Enter your password and click Click to copy below the input.
  • CLOUDFLARE_AUTH_EMAIL This is your account email address.

Step 5#

Install the dependencies:

npm install

Step 6#

Now you are ready to deploy the API with a simple command:

npm run deploy

Step 7#

That's it. Your API should now be available in the worldwide network of Cloudflare. Create your first avatar:

https://your-domain.com/4.5/api/male/seed.svg