A Flask API starter, served properly

Two dependencies, four example routes, waitress instead of the development server, and files that survive a redeploy.

The starter's routes answering on its web address.
Terminal
$ curl https://my-api.fadehost.app/api/hello?name=Ada
{"hello":"Ada"}
$ curl https://my-api.fadehost.app/health
{"ok":true}
$ curl https://my-api.fadehost.app/api/visits
{"storedIn":"/data","visits":3}
Plan
Free to try
Dependencies
Two: Flask, waitress
Runtime
Python 3.11 or newer
Keeps
Files under /data

What is in it

Served by waitress

Not Flask's development server, which warns you not to use it for real, and it is right.

Listens where it should

On PORT and 0.0.0.0. An app bound to localhost answers only itself, and its web address gets nothing.

Files that survive a redeploy

The app folder is cloned fresh on every deploy and /data is not. The visit counter proves it.

JSON errors and an app factory

A 404 or an exception answers JSON without a traceback, and the tests run the real routes against a temporary folder.

Set it up

  1. 1

    Make a copy

    Press Use this template on GitHub, or fork it.

  2. 2

    Deploy your copy

    Press Deploy free and pick your repository. It installs requirements.txt and runs python main.py by itself. Turn on the web address and the API answers at https://name.fadehost.app.

  3. 3

    Build on it

    Put your routes in api/app.py. Keep /health, the 0.0.0.0 bind and anything you cannot lose under /data. Every push redeploys it.

Routes

GET /
What the app is, and its routes.
GET /health
{ ok: true }
GET /api/hello?name=
{ hello: name }
POST /api/echo
Gives back the JSON you sent.
GET /api/visits
A counter kept under /data, to show it survives a redeploy.

Environment variables

They live in the table on the app's page in the panel, values masked once saved. Set for you means the panel fills it in when you deploy.

VariableNeededWhat it is
PORTSet for youThe port to listen on.
APP_URLSet for youThe public address, when the web address is on.
DATA_DIROptionalWhere to keep files: /data, or ./data where there is no /data.

Which plan it needs

The free plan runs it with an address that sleeps when idle, and the first request after a quiet spell waits a few seconds. An API other things depend on belongs on Starter.

Free

Recommended

$0

No card

  • 256 MB and a quarter of a CPU
  • The address sleeps when idle and wakes on the next visit
  • 1 GB of traffic a day

Starter

$2/mo

or $20 a year

  • Always awake, with 1 GB and a full vCPU
  • No traffic limit
  • A MySQL database included

Running more than one? Standard carries two bots or apps for $3 a month and Pro four for $6, on one bill with your game servers. Every plan

Frequently asked questions

Can I deploy it without a copy of my own?

Yes. In the panel, Host an app, then the Flask API starter template runs ours as it is. You need your own repository once you want to change the code.

Can I use gunicorn instead?

Yes. Add it to requirements.txt and set the start command to gunicorn -b 0.0.0.0:$PORT with your app. waitress is there because it needs no settings at all.

Where does a database go?

Paid apps include a MySQL database at no extra cost, and PostgreSQL, MongoDB and Redis sit on your private network as managed databases. For something small, SQLite in a file under /data works too.

Start your API from the starter

Your first app is free, with no card, and gets its own https address.

Use this template