APIO is part of the Monkiato's experiments, created with Golang and designed for running under Docker containers.
It's a dynamic Rest API where internal collections are declared in a JSON formatted manifest. APIO will read, parse, and populate all the endpoints required to interact with the API.
Github Docker registry for Monkiato provides a Docker image to be deployed easily, running a custom REST API in seconds.
How to use APIO
Pre-requisite
- Have a Mongo database running under the same network, either if it's running on Docker or not.
- Prepare APIO manifest file with collections and fields, e.g.
[
{
"name": "people",
"fields": {
"name": "string",
"birthday": "float",
"phone": "string"
}
}
]
(Sample file obtained from https://github.com/monkiato/apio/blob/master/manifest.sample.json)
Deploy APIO
This is Docker compose example running MongoDB and a single APIO node:
version: '3'
services:
apio:
build: .
volumes:
- "./manifest.json:/app/manifest.json"
environment:
MONGODB_HOST: "mongodb:27017"
MONGODB_NAME: apio
MONGODB_USERNAME: root
MONGODB_PASSWORD: example
DEBUG_MODE: 1
depends_on:
- mongodb
ports:
- 8000:80
mongodb:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
MONGO_INITDB_DATABASE: apio
(Sample file obtained from https://github.com/monkiato/apio/blob/master/docker-compose.yml)
Now APIO is up and running, the API will be running at http://localhost:8000/api
for the given example.
Multiple nodes management with Traefik proxy & APIO Orchestrator
We found Traefik a good complementary proxy, not only for security reasons, also to make everything more dynamic and be able to create new APIs on the fly.
That's why apio-orchestrator was created as a new experiment, in order to create multiple APIs on the fly, and get them available immediately through Traefik.
APIO Orchestrator is a CLI tool which simplifies the process to administrate multiple nodes. At the moment this post is written, it has been specifically designed to be used with Traefik, and all new nodes will be created with Traefik labels and accessible through this proxy only.
Once apio-orchestrator command is available, follow the checklist below and some sample command to interact with it.
Checklist
- Ensure Docker is up & running
- Modify default values through
config.json
file (sample file available in this folder modifies domain name and base config path) - Create Docker network for Traefik and APIO nodes (
docker network create apio-default
). If the network name is different from default, it must be declared inconfig.json
- Ensure Traefik and MongoDB are running under the same network (check docker-compose.yml sample file)
Run test
The environment is ready to run the orchestrator:
Create API node called notebook
using notebook.json manifest. A collection called people
will be available in this API.
api-orchestrator create notebook -m notebook.json
Remove node
apio-orchestrator remove notebook
Add collection and fields
apio-orchestrator createCollection notebook countries
apio-orchestrator createField notebook countries name
apio-orchestrator createField notebook countries country_code
Inspect API
apio-orchestrator inspect notebook