DEV Community

Cover image for Create your first Inversify HTTP API
notaphplover
notaphplover

Posted on

Create your first Inversify HTTP API

A running API is the fastest way to see what Inversify HTTP feels like. The scaffolded API already has controllers, request validation, OpenAPI docs, and a Postgres-backed todo list, so you can try a real project before you decide how to shape your own.

Start with one command

@inversifyjs/create-http asks for a package manager, an HTTP adapter, and an API style. It writes the project, installs the dependencies, and builds it.

npm create @inversifyjs/http@latest my-app
Enter fullscreen mode Exit fullscreen mode
pnpm create @inversifyjs/http my-app
Enter fullscreen mode Exit fullscreen mode
yarn create @inversifyjs/http my-app
Enter fullscreen mode Exit fullscreen mode

The prompts accept npm, pnpm, or yarn, an adapter (express, fastify, hono, or uwebsockets), and an API style (code-first or schema-first). Yarn projects use Yarn Berry, so run corepack enable once before the create command.

Run the sample

Todos live in PostgreSQL. Start the database from the generated docker-compose.yml, apply the migrations, and serve the API. Use the script names that match the package manager you picked (npm run, pnpm, or yarn).

cd my-app
docker compose up -d
npm run db:migrate
npm run serve
Enter fullscreen mode Exit fullscreen mode

Then open:

The generated .env sets DEV_PROFILER_ENABLED=true. With that flag on, the same server records each call and serves HTTP Insights at http://localhost:3000/.inversify/http-insights-ui. Send a few requests from the docs UI and open a call to see the middleware, the validation pipe, and the controller on one timeline.

Image

Where to go next

The getting started guide walks through the scaffold, then shows how to add the packages to a project you already have. Controllers are the next page after that.


Stuck on the generated project? Open an issue on GitHub or ask in Discord.

Top comments (0)