Live API examples

These scripts call the running website. No API key, database or third-party Python package is required. They compare straight-pipe water pressure loss at 20°C and 80°C while holding flow and geometry fixed.

Inputs and expected output

The example uses 200,000 Pa absolute inlet pressure, 0.001 m³/s flow, 20 m pipe length, 0.025 m internal diameter and 0.000015 m roughness. The calculation assumes isothermal, full-pipe flow in a horizontal straight pipe. It excludes fittings, elevation changes and pumps.

20 C: 37.95 kPa
80 C: 32.40 kPa

Higher temperature changes water density and viscosity in this model. See the water properties and pipe-flow guide for IAPWS references and validity limits. The difference is specific to these inputs.

JavaScript

Save the JavaScript example and run node water-pipe.mjs with Node.js 22 or later. It uses the built-in fetch client with a 15-second timeout.

// Run with Node.js 22 or later: node water-pipe.mjs
// SI inputs; isothermal, horizontal, full straight pipe without fittings.
const endpoint = 'https://www.engivault.com/api/hydraulics/water-pipe-loss';
async function calculate(temperature) {
  const response = await fetch(endpoint, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    signal: AbortSignal.timeout(15000),
    body: JSON.stringify({
      temperature, inletPressure: 200000,
      flowRate: 0.001, length: 20, diameter: 0.025, roughness: 0.000015
    })
  });
  const result = await response.json();
  if (!response.ok || !result.success) {
    throw new Error(result.error || `HTTP ${response.status}`);
  }
  return result.data;
}
try {
  for (const temperature of [20, 80]) {
    const result = await calculate(temperature);
    console.log(`${temperature} C: ${(result.pressureDrop / 1000).toFixed(2)} kPa`);
  }
} catch (error) {
  console.error(error.message);
  process.exitCode = 1;
}

Node.js fetch documentation, accessed September 8, 2026.

Python

Save the Python example and run python3 water-pipe.py. The standard-library HTTP client reports server error messages and uses a 15-second socket timeout.

# Run with Python 3: python3 water-pipe.py
# Uses the standard library. SI inputs; horizontal straight pipe without fittings.
import json
import sys
import urllib.error
import urllib.request

ENDPOINT = "https://www.engivault.com/api/hydraulics/water-pipe-loss"

def calculate(temperature):
    payload = {
        "temperature": temperature, "inletPressure": 200000,
        "flowRate": 0.001, "length": 20, "diameter": 0.025,
        "roughness": 0.000015,
    }
    request = urllib.request.Request(
        ENDPOINT, data=json.dumps(payload).encode("utf-8"),
        headers={"Content-Type": "application/json"}, method="POST",
    )
    try:
        with urllib.request.urlopen(request, timeout=15) as response:
            result = json.load(response)
    except urllib.error.HTTPError as error:
        try:
            message = json.load(error).get("error", str(error))
        except (ValueError, AttributeError):
            message = str(error)
        raise RuntimeError(message) from error
    if not result.get("success"):
        raise RuntimeError(result.get("error", "Calculation failed"))
    return result["data"]

if __name__ == "__main__":
    try:
        for temperature in (20, 80):
            result = calculate(temperature)
            print(f"{temperature} C: {result['pressureDrop'] / 1000:.2f} kPa")
    except (RuntimeError, urllib.error.URLError, TimeoutError, ValueError) as error:
        print(str(error), file=sys.stderr)
        sys.exit(1)

Python urllib.request documentation, accessed September 8, 2026.

Change the example

Edit the temperatures or pipe inputs while preserving their units. For other calculations, change both the endpoint and the JSON fields using the complete live API reference. Read the response from data, and check HTTP status before using it.

Both scripts exit with a nonzero status when a request fails. For an intentional domain-error check, set the inlet pressure to 100000 Pa and temperature to 110°C; this state falls below the liquid-water saturation-pressure boundary and is rejected.

These are scripts for Node.js and Python. Browser integrations on another domain also depend on that browser’s cross-origin rules; the examples do not establish a cross-origin browser SDK.

Back to quick start