Pre-requisites
Before you start ensure that your system or environment meets the following requirements:- Node.js (v18+) and npm (v9+) - Ensure that both Node.js and npm are up-to-date to support the latest features and security patches.
- pnpm (v6+) - Recommended for efficient package management and faster installations.
- Docker (v20+) - Docker should be properly installed and configured for containerization of your API Lab instance.
- Git - Required for version control and managing API Lab source code.
Configuring the Environment
Create a.env file in your working directory, copy the example environment variable configurations provided below into it, and then replace the example values with your actual values.
1. Database Configuration
API Lab uses a Postgres database to store all the data. You can use any Postgres database provider of your choice, hosted locally or on a cloud. Update theDATABASE_URL variable in your .env file with your custom database connection string, which should include the username, password, and database name.
2. SMTP Configuration
To invite your team to use API Lab and enable email delivery, you’ll need to configure SMTP settings properly.2.1 Basic SMTP Configuration
For basic SMTP configuration, you can use mailcatcher. It runs a super simple SMTP server which catches any message sent to it to display in a web interface. You can set up mailcatcher using Docker with 2 below easy steps:-
Pull the Mailcatcher Image from Docker Hub,
-
With Mailcatcher set up on your machine, start the Mailcatcher container using
docker runwith the appropriate port mappings (1080for the web interface and1025for SMTP).Docker containers are isolated from the host by default. When using localhost inside a Docker container, it refers to the container itself, and not the host machine. Since API Lab runs inside a Docker container while Mailcatcher runs on the host machine, you’ll need to use the Docker bridge network IP instead of
localhostto ensure that the containerized application can communicate with the Mailcatcher service on the host. To find this IP address, run:Look for the inet address associated with the docker0 interface. It’s typically in the 172.17.0.0/16 range but may vary based on your Docker network configuration. And If you’re using Docker Desktop, you can usehost.docker.internalinstead oflocalhost.Visithttp://<Docker_bridge_IP or host.docker.internal>:1080to access the Mailcatcher web interface and view email communications. Further, configure the below environment variables in your.envfile:
2.2 Custom Mailer Configuration
For advanced email delivery needs, such as for production environments, you can configure a custom email service by settingMAILER_USE_CUSTOM_CONFIGS=true. You can choose from services like SendGrid, Amazon SES, or your own SMTP server. Once you’ve set up your chosen service, update your .env file with the following details:
3. OAuth Configuration
To access the admin dashboard, you’ll need to configure an OAuth provider. In the Community Edition, API Lab supports:- GitHub
- Microsoft
- Click your profile photo in the upper-right corner and select Settings.
- In the left sidebar, scroll down and click Developer Settings.
- Click OAuth Apps in the sidebar.
- Click New OAuth App.
- Enter the required information and specify the callback URL as indicated in your configuration.
- After registering the application, copy the Client ID and Client Secret, and add them to your environment file.
4. Subpath Access
Subpath access allows you to host multiple services under a single domain by assigning each service a specific subpath. WhenENABLE_SUBPATH_BASED_ACCESS=true, you can access all three services (API Lab App, Admin Dashboard, API Lab Backend) on the same domain using different routes. If subpath access is disabled (ENABLE_SUBPATH_BASED_ACCESS=false), you will need to access the services on different ports.
Installing dependencies, running migrations & building the image
Once the environment variables are configured, you may now proceed to the next step of setting up the API Lab instance.1
Check Database Connectivity
Ensure that the database instance is active and running at the
DATABASE_URL specified in your .env file.2
Select the suitable API Lab instance to self-host
There are two ways to set up API Lab:
- Using individual containers for the services - API Lab Backend, API Lab Frontend and API Lab Admin Dashboard.
- Using the AIO container - a single container that provides all the services required to run API Lab.
3
Pull the latest API Lab container
Pull the container from DockerHub with the following command. If a specific version isn’t provided, it will automatically pull the latest version:
4
Run Database Migrations
After pulling the API Lab image from DockerHub, you need to run database migrations to set up the necessary tables. Use the following commands:
5
Start the API Lab Instance
To launch API Lab, run the container with the following command:
Accessing Admin Dashboard and Application
- Accessing the Admin Dashboard
- After successfully running the required containers, the next step is to create an Admin account.
- To access the Admin Dashboard, visit
http://localhost:3100ifENABLE_SUBPATH_BASED_ACCESS=false. - Log in with your credentials or create a new account to obtain admin privileges.
- Once logged in, you’ll find the Dashboard as your central hub for managing workspaces, overseeing user activities, and configuring OAuth environment variables directly from the Settings page.
- Accessing the API Lab Application
- You can access the API Lab application itself at
http://localhost:3000.
- You can access the API Lab application itself at
In conclusion, this guide has covered how to self-host API Lab, helping you set everything up in one go. If you prefer visual guidance, check out the video below for a detailed walkthrough that complements the instructions provided here. For additional details on each step of self-hosting API Lab, refer to our documentation.