Integration

REST API Integration

Complete examples for integrating NextReport from Python, Java, C#, and curl.

Overview

NextReport Engine exposes a REST API that any HTTP client can call. This page provides complete, copy-paste examples in multiple languages for the most common operations.

Python

Render HTML

import requests

response = requests.post("http://localhost:3000/api/render", json={
    "templateId": "invoice-v1",
    "data": {
        "company": {"name": "Acme Corp"},
        "invoiceNumber": "INV-001",
        "items": [
            {"description": "Consulting", "quantity": 8, "unitPrice": 150, "total": 1200}
        ]
    },
    "format": "html"
})

result = response.json()
html_output = result["output"]
print(f"Rendered {result['metadata']['pageCount']} page(s)")

Download PDF

import requests

response = requests.post("http://localhost:3000/api/render", json={
    "templateId": "invoice-v1",
    "data": {
        "company": {"name": "Acme Corp"},
        "invoiceNumber": "INV-001",
        "items": [
            {"description": "Consulting", "quantity": 8, "unitPrice": 150, "total": 1200}
        ]
    },
    "format": "pdf"
})

with open("invoice.pdf", "wb") as f:
    f.write(response.content)

print("PDF saved to invoice.pdf")

Java

Render HTML

import java.net.http.*;
import java.net.URI;

public class ReportClient {
    public static void main(String[] args) throws Exception {
        var client = HttpClient.newHttpClient();

        var body = """
            {
                "templateId": "invoice-v1",
                "data": {
                    "company": {"name": "Acme Corp"},
                    "invoiceNumber": "INV-001",
                    "items": [
                        {"description": "Consulting", "quantity": 8, "unitPrice": 150, "total": 1200}
                    ]
                },
                "format": "html"
            }
            """;

        var request = HttpRequest.newBuilder()
            .uri(URI.create("http://localhost:3000/api/render"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(body))
            .build();

        var response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

Download PDF

import java.net.http.*;
import java.net.URI;
import java.nio.file.*;

public class PdfDownload {
    public static void main(String[] args) throws Exception {
        var client = HttpClient.newHttpClient();

        var body = """
            {
                "templateId": "invoice-v1",
                "data": {
                    "company": {"name": "Acme Corp"},
                    "invoiceNumber": "INV-001",
                    "items": [
                        {"description": "Consulting", "quantity": 8, "unitPrice": 150, "total": 1200}
                    ]
                },
                "format": "pdf"
            }
            """;

        var request = HttpRequest.newBuilder()
            .uri(URI.create("http://localhost:3000/api/render"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(body))
            .build();

        var response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
        Files.write(Path.of("invoice.pdf"), response.body());
        System.out.println("PDF saved to invoice.pdf");
    }
}

C#

Render HTML

using System.Net.Http.Json;

var client = new HttpClient();

var response = await client.PostAsJsonAsync("http://localhost:3000/api/render", new
{
    templateId = "invoice-v1",
    data = new
    {
        company = new { name = "Acme Corp" },
        invoiceNumber = "INV-001",
        items = new[]
        {
            new { description = "Consulting", quantity = 8, unitPrice = 150, total = 1200 }
        }
    },
    format = "html"
});

var result = await response.Content.ReadFromJsonAsync<RenderResult>();
Console.WriteLine($"Rendered {result.Metadata.PageCount} page(s)");

record RenderResult(string Output, RenderMetadata Metadata);
record RenderMetadata(int PageCount, int RenderTimeMs, string Format);

Download PDF

using System.Net.Http.Json;

var client = new HttpClient();

var response = await client.PostAsJsonAsync("http://localhost:3000/api/render", new
{
    templateId = "invoice-v1",
    data = new
    {
        company = new { name = "Acme Corp" },
        invoiceNumber = "INV-001",
        items = new[]
        {
            new { description = "Consulting", quantity = 8, unitPrice = 150, total = 1200 }
        }
    },
    format = "pdf"
});

var pdfBytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("invoice.pdf", pdfBytes);
Console.WriteLine("PDF saved to invoice.pdf");

curl

Render HTML

curl -X POST http://localhost:3000/api/render \
  -H "Content-Type: application/json" \
  -d '{
    "templateId": "invoice-v1",
    "data": {
      "company": {"name": "Acme Corp"},
      "invoiceNumber": "INV-001",
      "items": [
        {"description": "Consulting", "quantity": 8, "unitPrice": 150, "total": 1200}
      ]
    },
    "format": "html"
  }'

Download PDF

curl -X POST http://localhost:3000/api/render \
  -H "Content-Type: application/json" \
  -o invoice.pdf \
  -d '{
    "templateId": "invoice-v1",
    "data": {
      "company": {"name": "Acme Corp"},
      "invoiceNumber": "INV-001",
      "items": [
        {"description": "Consulting", "quantity": 8, "unitPrice": 150, "total": 1200}
      ]
    },
    "format": "pdf"
  }'

Validate a template

curl -X POST http://localhost:3000/api/validate \
  -H "Content-Type: application/json" \
  -d '{
    "template": {
      "version": "1.0",
      "type": "report",
      "page": {"size": "A4", "orientation": "portrait"},
      "bands": []
    }
  }'

Next steps