Effortless backends with infrastructure from code.
An open source universal backend framework, with concise infrastructure and pluggable deployment automation.
import { api, bucket } from "@nitric/sdk";const main = api("main");const notes = bucket("notes").allow("read", "write");main.get("/notes/:title", async ({req, res}) => {const { title } = req.params;res.body = await notes.file(title).read();});main.post("/notes/:title", async ({req, res}) => {const { title } = req.params;await notes.file(title).write(req.text());});
Why Nitric?
Nitric is a multi-language backend framework that lets you declare infrastructure requirements in code for common cloud resources and provides a convenient interface to interact with them.
Using Terraform, Pulumi, or any tool you prefer, Nitric plugins automate cloud resource provisioning, security and linking. Nitric provides plugins for AWS, Azure and Google Cloud out of the box, then extend or build your own when things get custom.
Deploy Anywhere
Supported Resources
APIs
APIs
You can easily create APIs using Nitric. With a familiar syntax, it's simple to define your routes, middlewares, and handlers all from the comfort of your application code.
import { api } from "@nitric/sdk"const main = api("main")main.get("/hello/:name", (ctx) async {const { name } = ctx.req.paramsctx.res.body = `Hello ${name}`return ctx;})
Writing authentication and authorisation for your API is as simple as adding security definitions to your API resource. Integrates with any OIDC-compatible providers such as Auth0, FusionAuth, and AWS Cognito.
import { api, oidcRule } from '@nitric/sdk'const defaultSecurityRule = oidcRule({name: 'default',audiences: ['https://test-security-definition/'],issuer: 'https://dev-abc123.us.auth0.com',})const secureApi = api('main', {security: [defaultSecurityRule('user.read')],})
APIs automatically deploy to API Gateway services like AWS API Gateway, Google Cloud API Gateway, or Azure API Management.
Route handlers are automatically built as containers and deployed to serverless container runtimes like AWS Lambda, Google CloudRun, or Azure Container Apps
Batch (AI & Data)
Batch (AI & Data)
Access high-performance data and AI services like AWS Batch, Google Cloud Batch and Azure Batch using the Nitric Batch resources.
Completely customize the resources required for your long running jobs and access the latest GPUs that the clouds have to offer.
import { job } from "@nitric/sdk"const genImages = job("generate-image");genImages.handler(async (data) => {// do something amazing},{ cpus: 4, memory: 16384, gpus: 1 },);
Send tasks to batch services from any other service.
await genImages.submit({});
Databases
Databases
Deploy Postgres SQL databases with 1 line of code to managed database services like AWS RDS, Google Cloud SQL or Azure Database for PostgreSQL with Nitric.
import { database } from "@nitric/sdk";import { client } from "your-database-client";import { users } from "../schema";const db = database("db");const getDbClient = async () => {const connectionString = db.connectionString();return client(connectionString);};const addUser = async (user) => {const db = await getClient();await db.insert(users, user);};
Migrations act as version control for your database, enabling progressive schema updates without the worry.
const db = database("db", {migrations: "file://migrations",});
Storage
Storage
Read, write, and delete large files to serverless object stores like Amazon S3, Google Cloud Storage, or Azure Blob Storage with Nitric's Bucket API.
import { bucket } from '@nitric/sdk'const profiles = bucket('profile-images').allow('write')await profiles.file('profiles/user-343.jpg').write(imageData)
Define reactive eventing for your storage workflows using Bucket Notifications.
import { bucket } from '@nitric/sdk'const profiles = bucket('profile-images')profiles.on('delete', '*', (ctx) => {console.log(`${ctx.req.key} image was deleted`)})
Messaging
Messaging
Implement pub/sub or queue-based messaging for real-time event handling, fan-out, task-driven workloads and more.
Nitric supports many popular Queue and Topic services, such as Amazon SQS, Amazon SNS, Google Pub/Sub, Azure Event Grid and Azure Storage Queues.
For pub/sub, define Topics, Publishers and Subscribers, then publish messages to a topic and have them reactively handled by subscribers.
import { topic, api } from "@nitric/sdk";const events = topic("events").allow("publish");// Publish messages from any service, such as APIs.api('public').post('/users', async ({req, res}) => {const userData = req.json()await events.publish({type: 'user.created',details: userData,})}
Define subscribers to handle events asynchronously.
import { topic } from "@nitric/sdk";const events = topic("events");events.subscribe(async (ctx) => {// Extract data for processingconst { details } = ctx.req.json()logEvent(details)})
If you want to offload processing of messages from your main API calls you can use a Queue and write a service to handle events separately.
import { queue } from '@nitric/sdk'const transactionQueue = queue('transactions').allow('enqueue')await transactionQueue.enqueue({message: 'hello world',})
Websockets
Websockets
Build apps with presence, realtime and multiplayer collaboration using WebSockets. Backed by cloud services like Amazon API Gateway.
Nitric's websockets allow you to send and listen for messages between services, and connections can be stored using a Nitric Key Value Store resource.
import { websocket, kv } from '@nitric/sdk'const conns = kv('connections').allow('get')const socket = websocket('presence')// Broadcast updatessocket.on('message', async (ctx) => {for await (const connectionId of conns.keys()) {await socket.send(connectionId, ctx.req.text())}})
Schedules
Schedules
Build and deploy scheduled tasks and jobs to run at specific times or intervals, written in plain language.
import { schedule } from '@nitric/sdk'const process = schedule('process-transactions');process.every('15 minutes', async () => {processTransaction()})
Or you can get custom and use Cron scheduling, up to you.
process.cron('*/15 * * * *', async () => {processTransaction()})
Scheduled services automatically build and deploy to container runtimes like AWS Lambda, Google CloudRun, or Azure Container Apps
Run Local. Iterate Faster.
$ nitric start
Instant Compatibility
streamline your development workflow
ship faster with next generation infrastructure automation using nitric.