Skip to main content
Version: 2.30.1

Programmatic API

In many cases it's useful to start Platformatic Composer using an API instead of command line, e.g. in tests we want to start and stop our server.

The buildServer function allows that:

import { buildServer } from '@platformatic/composer'

const app = await buildServer('path/to/platformatic.composer.json')
await app.start()

const res = await fetch(app.url)
console.log(await res.json())

// do something

await app.close()

It is also possible to customize the configuration:

import { buildServer } from '@platformatic/composer'

const app = await buildServer({
server: {
hostname: '127.0.0.1',
port: 0
},
services: [
{
id: 'auth-service',
origin: 'https://auth-service.com',
openapi: {
url: '/documentation/json',
prefix: 'auth'
}
},
{
id: 'payment-service',
origin: 'https://payment-service.com',
openapi: {
file: './schemas/payment-service.json'
}
}
]
})

await app.start()

const res = await fetch(app.url)
console.log(await res.json())

// do something

await app.close()

Issues

If you run into a bug or have a suggestion for improvement, please raise an issue on GitHub or join our Discord feedback channel.