What Are Webhooks?
A webhook lets Werk24 push extraction results to your server once a drawing has been processed. Instead of waiting for messages over a persistent connection, you register a URL and handle the incoming HTTP requests in your own application. This pattern is especially useful when your backend is written in another language—such as Java, JavaScript/Node.js, C#, Go, PHP, Ruby, or Rust—because all you need to implement is a standard HTTPS endpoint.
Register a Callback
Use the read_drawing_with_callback
method of Werk24Client
to send a drawing and register your callback URL:
from werk24 import Werk24Client, AskMetaData
async def submit(drawing_bytes: bytes):
async with Werk24Client() as client:
request_id = await client.read_drawing_with_callback(
drawing_bytes,
[AskMetaData()],
"https://example.com/webhook",
callback_headers={"X-Token": "my-shared-secret"},
)
print(f"Registered request: {request_id}")
Node.js equivalent
import fetch from 'node-fetch';
import FormData from 'form-data';
import fs from 'fs';
const LICENSE_TOKEN = 'YOUR_WERK24_TOKEN';
const SECRET = 'my-shared-secret';
async function submit() {
const form = new FormData();
form.append('drawing', fs.createReadStream('drawing.pdf'));
form.append('asks', JSON.stringify([{ kind: 'meta_data' }]));
form.append('callback_url', JSON.stringify('https://example.com/webhook'));
form.append('callback_headers', JSON.stringify({ 'X-Token': SECRET }));
form.append('max_pages', JSON.stringify(5));
const res = await fetch('https://api.w24.co/techread/read-with-callback', {
method: 'POST',
headers: { ...form.getHeaders(), Authorization: `Token ${LICENSE_TOKEN}` },
body: form,
});
const { request_id } = await res.json();
console.log('Registered request:', request_id);
}
submit().catch(console.error);
Parameters
callback_url
– URL that will receive POST requests containingTechreadMessage
objects.callback_headers
– Optional headers included with the request. Headers must start withX-
or be explicitly whitelisted (e.g.,Authorization
).public_key
– Optional PEM encoded public key used to encrypt the payload.
The method returns a request_id
which you can use to correlate the asynchronous callbacks with your system.
Works with Any Stack
Because callbacks are just HTTPS requests, you can receive them in virtually any programming language.
Handle the Callback in Node.js
Here is a minimal Express server that logs the incoming message and verifies a custom header:
const express = require('express');
const app = express();
app.use(express.json());
const SECRET = 'my-shared-secret';
app.post('/webhook', (req, res) => {
if (req.get('X-Token') !== SECRET) {
return res.status(401).send('Unauthorized');
}
const { request_id, ask, payload } = req.body;
console.log('Received:', request_id, ask, payload);
res.sendStatus(200);
});
app.listen(3000, () => console.log('Webhook server running on port 3000'));
Expose this endpoint over HTTPS and set the callback URL to https://your-host/webhook
when submitting the drawing.
Supported languages include:
- Java
- JavaScript / Node.js
- TypeScript
- C#
- Go
- PHP
- Ruby
- Rust
- C++
When to Use Webhooks
Webhooks are ideal for integrations where long‑lived connections are impractical or when you do not want to run a Python client. Because Werk24 sends results via ordinary HTTP POST requests, any language or framework that can handle web requests can consume them—for example Java, JavaScript/Node.js, TypeScript, C#, Go, PHP, Ruby, or Rust. Register the callback and process the results whenever Werk24 calls your endpoint.