HTTP
Nitric supports existing web app and API frameworks, including Express, Koa, Fastify and many more. The http
resource allows you to connect Nitric to your existing applications. When deployed, this resource deploys a unique HTTP API Gateway in your chosen cloud provider and routes all incoming requests to your HTTP application.
The HTTP resource is currently only supported for Node.js projects. If you would like support for another language let us know: https://github.com/nitrictech/nitric/issues
Overview
The HTTP resource is particularly useful when you want to:
- Use existing web frameworks without modification
- Leverage framework-specific features and middleware
- Maintain compatibility with existing codebases
- Deploy traditional web applications to the cloud
Connecting existing frameworks
Here are examples of how to connect popular Node.js frameworks with Nitric:
import { http } from '@nitric/sdk'import express from 'express'const app = express()app.use('/hello', (req, res) => {res.send('hello from express')})http(app)
Best Practices
-
Middleware Order: Place Nitric's
http()
call after all your middleware and route definitions. -
Error Handling: Use your framework's error handling middleware to ensure consistent error responses.
-
Environment Variables: Access environment variables through your framework's configuration system.
-
Logging: Use your framework's logging system for consistent application logging.
Cloud Service Mapping
Each cloud provider comes with a set of default services used when deploying resources. You can find the default services for each cloud provider below.