Subscribe to document changes in real-time. Trigger builds, update your CMS, or alert your team whenever you hit publish.
Secure your endpoint
We send a secret key in the headers so you can verify the request came from Mrakdon.
// app/api/webhooks/mrakdon/route.ts
import { NextResponse } from "next/server";
export async function POST(req: Request) {
const secret = process.env.MRAKDON_SECRET;
const signature = req.headers.get("X-Markdown-Key");
// 1. Validate Security Header
if (signature !== secret) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
// 2. Process Payload
const body = await req.json();
console.log("New Post:", body.document.title);
return NextResponse.json({ received: true });
}{
"event": "publish",
"timestamp": "2024-01-20T10:00:00Z",
"document": {
"id": "doc_12345",
"title": "My Awesome Blog Post",
"slug": "my-awesome-blog-post",
"content": "# Hello World\n\nThis is markdown...",
"html": "<h1>Hello World</h1><p>...</p>",
"author": {
"id": "user_99",
"name": "Dev User"
}
}
}eventStringType of event (e.g., 'publish').
document.contentMarkdownThe raw generated markdown.
document.htmlHTMLRendered HTML (optional).
document.slugStringURL friendly slug for the post.
Acknowledge receipt immediately.
We retry 3 times if we don't get a 200 OK.
Please respond within 10 seconds.