/ New Features

Introducing the Fly API

We're excited to announce that our API is available for public usage. Fly.io is an Application Delivery Network; our API grants you code-level access to a global network of smart proxies. You can...

  • Add hostnames and receive a customized, automatically renewing Let's Encrypt HTTPS certificate.
  • Add any backend from our growing library; Amazon S3, AWS Lambda, self-hosted applications, container-hosted applications, Heroku, GitHub Pages, Square Space, to name a handful.
  • Configure rules so that you have full control over how to route to your different backends and hostnames.

We'll look into a powerful use-case that gives you a peek into how you can leverage the Fly API to speed up your applications and better load balance and serve sites to your users. First, we'll look into what we have available today.

API magic with cartoons

First Wave

Presently, you can make requests to the following resources:

  • POST, GET for /api/v1/sites/:slug/hostnames
  • GET for /api/v1/sites/:slug/hostnames/:hostname
  • POST for /api/v1/sites/:slug/backends
  • POST for /api/v1/sites/:slug/rules

We have in-depth documentation available if you'd like to jump right in. If you need some inspiration regarding how to apply the API, keep reading!

Oh My, API.

We'll make up a fictional use-case. Let's say we have a company, Oh My Web Design, that designs, develops, and hosts websites for customers looking to turn their crazy ideas into functional sites and applications. While they excel at making beautiful applications, things tend to slow down when its time to add secure HTTPS, configure a reliable load balancer, implement analytic tracking and optimize for fast speeds to a global user-base.

Using the Fly.io API for each site they build, they can:

  • POST to /api/v1/sites/:slug/hostnames. They can easily add a new hostname under their organization's site. Let's consider that they have a new customer, perhaps radicalapp.com. They POST the new hostname and receive an HTTPS-encrypted Fly.io preview domain in return. With this domain, they create a new DNS record within radicalapp.com. It might look something like this...
curl -H "Content-Type: application/json" -X POST -d '{"data": { "attributes": { "hostname": "radicalapp.com" } } }' http://fly.io/api/v1/sites/oh-my-api/hostnames
  • POST to /api/v1/sites/:slug/backends. Under the Oh My Web Design site, they can add a medley of different backends. If radicalapp.com is hosted on Heroku, for instance, they can POST to /backends/ to add it on the fly. Here's how that would look:
curl -H "Content-Type: application/json" -X POST -d '{ "data": { "attributes": { "name": "Radical App - Heroku", "type": "heroku", "settings": { "heroku_app": "radicalapp.herokuapp.com" } } } }' https://fly.io/api/v1/sites/oh-my-api/backends
  • POST to /api/v1/sites/:slug/rules. With various backends and a multitude of hostnames, having the ability to write clean routing rules is essential. They can POST new rules that apply to respective hostnames and backends; they can set the priority, whether it's a rewrite or redirect, the path to match on - like /blog/ for a Ghost Blog or /docs/ for GitHub Pages - and whether any path replacements are required. Like so:
curl -H "Content-Type: application/json" -X POST -d '{ "data": { "attributes": { "hostname": "radicalapp.com", "backend_id": "je8928dk2", "action_type": "rewrite", "path": "/", "priority": "null", "path_replacement": "null"  } } }' https://fly.io/api/v1/sites/oh-my-api/rules

With a few powerful POSTs, Oh My Web Design has their new site hosted on an Application Delivery Network that provides Let's Encrypt HTTPS for security, global load balancing for redundancy and speed, and a library of useful Middleware; with Middleware, in a few clicks you can add Google Analytics, Render Speed Tracking, Geo IP Lookup and more at the server. No messing with complicated proxies required.

If you want to learn more, leap into our documentation! If the API doesn't cover your use-case, send us an email. Fly is free to sign up. Each month, your first 2,000,000 requests and 100GB of transfer are free.

Kellen Evan Person


Kellen Evan Person

A polite, forest-dwelling Canadian who enjoys coding and writing. He's spent near two decades building web applications and strives to keep development fun and light-hearted.

North Vancouver, Canada