Skip to content

Accessing Container APIs After compose.up

To access the APIs of your containers after running compose.up, make sure to set the apis parameter to true. This will include the apis object in the result, where each container’s id is mapped to its api from the start function.

Example

const a = createContainer({
id: 'a',
start: () => ({ api: { t: () => true } }),
});
const b = createContainer({
id: 'b',
start: () => ({ api: { f: () => false } }),
});
const result = await compose.up([a, b], { apis: true });
// Access the APIs
console.log(result.apis.a?.t()); // Outputs: true
console.log(result.apis.b?.f()); // Outputs: false

Notes

  • Ensure that the apis parameter is set to true to retrieve the apis object.
  • Each key in result.apis corresponds to the id of a container, and the value is the api defined in that container’s start function.
  • Important: The keys in apis are always optional because, at the type level, we cannot determine if a container has transitioned to the done status.