@intentrail/http
v1.0.0
Published
HTTP middleware helpers for serving IntentRail manifests
Maintainers
Readme
@intentrail/http
HTTP middleware helpers for serving IntentRail manifests.
Installation
npm install @intentrail/http
# or
pnpm add @intentrail/httpExpress
import express from "express";
import { createExpressHandler } from "@intentrail/http";
const app = express();
app.get("/intent/:id", createExpressHandler({
getIntent: async (id) => {
return await db.intents.findById(id);
},
}));
app.listen(3000);Fastify
import Fastify from "fastify";
import { createFastifyPlugin } from "@intentrail/http";
const app = Fastify();
app.register(createFastifyPlugin({
getIntent: async (id) => {
return await db.intents.findById(id);
},
}));
app.listen({ port: 3000 });Status Endpoint
import { InMemoryStatusStore, createStatusHandler, createPendingStatus } from "@intentrail/http";
const store = new InMemoryStatusStore();
// Create pending status when intent is submitted
await store.set(createPendingStatus(intentId));
// Query status
const handler = createStatusHandler(store);
app.get("/status/:intentId", async (req, res) => {
const status = await handler(req.params.intentId);
res.json(status);
});License
MIT
