Skip to main content

Getting started

Install dependencies

To get started with Inversify HTTP OpenAPI, first install the required packages.

Begin by installing the inversify packages and reflect-metadata:

  npm install inversify reflect-metadata @inversifyjs/http-core @inversifyjs/http-open-api
warning

Make sure to enable the Experimental Decorators and Emit Decorator Metadata options in your tsconfig.json.

Choose an HTTP adapter with OpenAPI support

Inversify HTTP OpenAPI works with several HTTP frameworks. Choose the adapter and OpenAPI provider that best fits your needs:

  npm install @inversifyjs/http-express-v4 @inversifyjs/express-4-open-api

Configure server

After installing the packages, create a server to listen for incoming requests. Below is a basic example of setting up an Express server with Inversify HTTP.

const container: Container = new Container();

const adapter: InversifyExpressHttpAdapter = new InversifyExpressHttpAdapter(
container,
);

const swaggerProvider: SwaggerUiExpressProvider =
new SwaggerUiExpressProvider({
api: {
openApiObject: {
info: {
title: 'My awesome API',
version: '1.0.0',
},
openapi: '3.1.1',
},
path: '/docs',
},
ui: {
title: 'My awesome API docs',
},
});

swaggerProvider.provide(container);

const application: express.Application = await adapter.build();

application.listen(3000);

The server is ready to receive requests, but there are no handlers yet. Add a Controller to handle incoming requests.