This Go API implements the OpenDI standard API definition.
Intended for local use, for demonstration purposes, this implementation will be available as a Docker image for easy local deployment.
This API allows for basic CRUD operations to be performed on a Causal Decision Model database, allowing for simple persistence in any service that uses the CDM data schema.
This project is implemented as a simple Go API, using the Gin Web Framework for API endpoint implementation, and GORM for object-relational mapping from Go typedefs to SQL data schemas.
This API is mainly intended to be used as part of the Containerized Authoring Demo. See that repo for instructions on running the whole project.
To run the API individually,
- Install Docker Desktop or some other form of the Docker Engine.
- Download the latest image for the OpenDI Go API from DockerHub (TODO: Host image on DockerHub). If this is impossible or unavailable, see Building the API for instructions on building your own image.
- Run a container from the image. See step 4 for Docker Desktop instructions, or step 5 for command line instructions.
- Docker Desktop instructions:
- In Docker Desktop, locate the image in
Images
and click the Play button. - Expand
Optional settings
and locate thePorts
section. - Set
Host port
to8080
. This is the port that the CDD builder frontend expects to use for API calls. - Click
Run
.
- In Docker Desktop, locate the image in
- Command line instructions:
- Execute the following command:
docker run -p 8080:8080 opendi-api
- The
-p
flag maps the local port8080
to the corresponding port8080
in the container. This is the port that the CDD builder frontend expects to use for API calls.
- Execute the following command:
- Test the connection. Use a REST API testing software like Insomnia, or try a command like
curl
:curl http://localhost:8080/v0/models
should return a JSON-formatted array of Meta objects with CDM IDs, names, etc.
To build an updated version of the API using local project files,
- Install Docker Desktop or some other form of the Docker Engine.
- Clone this GitHub repository.
- Within the parent directory for the cloned repository, run the following command:
docker build -t opendi-api .
These steps should build a new Docker image using the dockerfile in this repo. The build process has several steps, and may take 2-3 minutes.
This process will create a temporary Docker image and container to create build artifacts for the Go API program, then copy those artifacts into a final runtime image. The final image can be run using the steps in Running the API above, starting with step 3.