Skip to main content

Quickstart

An installation on one machine: Otoroshi, PostgreSQL and the product, run as they would be in production — the executable of a release, a configuration of its own —, then a first API, subscribed to by a consumer and called through the gateway. Everything runs on your machine: the domains *.oto.tools resolve to 127.0.0.1.

To work on the product itself — its development stack, its tests — see Development.

What you need​

Java 21 or laterto run Otoroshi
Dockerto run PostgreSQL — or a PostgreSQL 14 or later of your own
Otoroshi 18.1the jar of its release (below)
The productthe executable of a release, for linux or macOS, x64 or arm64
opensslto make the secrets of the installation

1. A folder and its configuration​

The installation lives in a folder: the configuration of Otoroshi and of the product, their secrets made once — keep the files, they hold them.

mkdir apim && cd apim
OTO_SECRET=$(openssl rand -hex 24)

cat > otoroshi.env <<EOF
OTOROSHI_INITIAL_ADMIN_LOGIN=admin@example.com
OTOROSHI_INITIAL_ADMIN_PASSWORD=$(openssl rand -hex 12)
OTOROSHI_ADMIN_API_CLIENT_ID=otoroshi-admin
OTOROSHI_ADMIN_API_CLIENT_SECRET=$OTO_SECRET
APP_STORAGE=file
OTOROSHI_FILEDB_PATH=./otoroshi-state.ndjson
EOF

cat > apim.env <<EOF
APIM_PUBLIC_URL=http://localhost:9000
APIM_DATABASE_URL=postgres://apim:apim-db-password@localhost:5432/apim
APIM_ANALYTICS_DATABASE_URL=postgres://apim:apim-db-password@localhost:5432/apim_analytics
APIM_SECRETS_KEY=$(openssl rand -hex 32)
APIM_ADMIN_TOKEN=$(openssl rand -hex 24)
APIM_INGEST_TOKEN=$(openssl rand -hex 24)
APIM_BOOTSTRAP_ADMINS=admin@example.com
APIM_BOOTSTRAP_PASSWORD=$(openssl rand -hex 12)
OTOROSHI_URL=http://localhost:8080
OTOROSHI_HOST=otoroshi-api.oto.tools
OTOROSHI_CLIENT_ID=otoroshi-admin
OTOROSHI_CLIENT_SECRET=$OTO_SECRET
OTOROSHI_PUBLIC_SCHEME=http
OTOROSHI_PUBLIC_PORT=8080
EOF

apim.env is the configuration of the product: a product missing one of these variables does not start, and says which.

2. PostgreSQL​

Two databases: the application data, and the events and analytics.

docker run -d --name apim-postgres -p 5432:5432 \
-e POSTGRES_USER=apim -e POSTGRES_PASSWORD=apim-db-password -e POSTGRES_DB=apim \
postgres:17
# once it accepts connections, a few seconds later
docker exec apim-postgres createdb -U apim apim_analytics

3. Otoroshi​

Download the jar of its release into the folder of the installation, and check it — its checksum file holds the digest alone:

curl -fLO https://github.com/MAIF/otoroshi/releases/download/v18.1.0/otoroshi.jar
curl -fLO https://github.com/MAIF/otoroshi/releases/download/v18.1.0/otoroshi.jar.sha256
echo "$(cat otoroshi.jar.sha256) otoroshi.jar" | sha256sum -c - # macOS: shasum -a 256 -c -

Start it, in a terminal of its own:

set -a; . ./otoroshi.env; set +a
java -jar otoroshi.jar

It listens on 8080. Its admin API is otoroshi-api.oto.tools, with the key of otoroshi.env; its state is kept in otoroshi-state.ndjson. Its own console is at http://otoroshi.oto.tools:8080 — you will not need it.

4. The product​

Download the executable of your system — linux-x64, linux-arm64, darwin-x64 or darwin-arm64 — and check it. During the beta the repository is private: gh, signed in with an account that has access, or the page of the release in a browser.

gh release download v0.1.1 -R cloud-apim/otoroshi-api-management \
-p 'otoroshi-apim-linux-x64' -p SHA256SUMS
sha256sum --ignore-missing -c SHA256SUMS # macOS: shasum -a 256 -c SHA256SUMS
mv otoroshi-apim-linux-x64 otoroshi-apim && chmod +x otoroshi-apim

Set the gateway up: the product makes its own admin key on Otoroshi, and the data exporter that sends it the events of the gateway — run it first with --dry-run to see what it would change.

set -a; . ./apim.env; set +a
./otoroshi-apim setup --only key,exporter --product-url http://localhost:9000 \
--admin-client-id "$OTOROSHI_CLIENT_ID" --admin-client-secret "$OTOROSHI_CLIENT_SECRET"
✓ key changed
+ Apikey apim_product_admin (otoroshi-api-management)
✓ exporter changed
+ DataExporter apim_ingester_exporter (otoroshi-api-management ingester)
events go to http://localhost:9000/ingest: the gateway must reach it
Checks
✓ Otoroshi 18.1.0, …
✓ the product calls the gateway with its own key, apim_product_admin
! no event reached the ingester for 15 minutes: …

The last line is expected: nothing has called the gateway yet. Then start the product, in a terminal of its own — it makes the tables of its databases at start:

set -a; . ./apim.env; set +a
./otoroshi-apim
[apim] bootstrap admin created: admin@example.com
[apim] bootstrap workspace created: default
[apim] listening on http://localhost:9000/ with roles: ingester, api, backoffice, portal

5. Sign in​

The consolehttp://localhost:9000/backoffice/admin@example.com, and the password grep APIM_BOOTSTRAP_PASSWORD apim.env gives
The developer portal of the workspace defaulthttp://localhost:9000/default/anyone can create an account
The admin APIhttp://localhost:9000/apiAuthorization: Bearer <APIM_ADMIN_TOKEN>

6. A first API​

From the console, the tutorial shows it a screen at a time. From a file, here a declarative document: an API that answers with the request it received, and a plan whose keys are issued at once.

hello.yaml
apiVersion: otoroshi-apim.io/v1
kind: Api
metadata:
name: hello
spec:
name: Hello
version: 1.0.0
description: The request it received, sent back
draft:
entrypoint:
domain: hello.oto.tools
contextPath: /
backends:
- id: backend_request
name: request
targets:
- { hostname: request.otoroshi.io, port: 443, tls: true, weight: 1 }
resources:
- { id: res_all, name: Everything, path: /, methods: [], backendId: backend_request }
plans:
- id: plan_free
name: Free
description: A key at once, 10 calls a second.
status: published
auth: { kind: apikey }
rateLimit: { enabled: true, calls: 10, windowMs: 1000 }
validation: auto

The command line is the same executable:

export APIM_URL=http://localhost:9000 APIM_TOKEN=$APIM_ADMIN_TOKEN
./otoroshi-apim apply default -f hello.yaml --publish --deploy
api hello 1.0.0 created, snapshot 1, deployed

The gateway serves it, and wants a key:

curl -i http://hello.oto.tools:8080/
HTTP/1.1 401 Unauthorized
Otoroshi-Error-Msg: You're not authorized here !

7. Subscribe, call, see the traffic​

On the portal, http://localhost:9000/default/: Create account, the API Hello, Plans → Subscribe, a new application. The plan approves at once: the client id and the client secret are shown. Then:

curl -i http://hello.oto.tools:8080/hello -u '<client id>:<client secret>'

200, and the request request.otoroshi.io received. A few seconds later, the call is in Usage on the portal, and in Observability in the console, attributed to the API, the plan and the application.

Next​

  • The console and the portals through the gateway, with TLS: the console and portals parts of the setup.
  • A production installation: Install — the roles split across instances, the container image, Kubernetes and Helm, the secrets at rest.
  • Sign in with your identity provider: Authentication.
  • The whole journey in the console and the portal: the tutorial.

To stop: Ctrl-C in both terminals, and docker stop apim-postgres. Everything is kept — the databases in their container, the state of Otoroshi in otoroshi-state.ndjson: docker start apim-postgres, then Otoroshi and the product with the same commands as above.