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
- pnpm
- yarn
npm install inversify reflect-metadata @inversifyjs/http-core @inversifyjs/http-open-api
pnpm install inversify reflect-metadata @inversifyjs/http-core @inversifyjs/http-open-api
yarn add 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.
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. You may set your server up with other supported frameworks like Hono or uWebSockets as well.
const container: Container = new Container();
const adapter: InversifyExpressHttpAdapter = new InversifyExpressHttpAdapter(
container,
);
const swaggerProvider: SwaggerUiProvider = new SwaggerUiProvider({
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.