SDK

Use the BARFLAB public API from Java, Python, or Node.js.

Generate a local client

Public packages are not published yet for Java, Python, or Node.js. Generate a local client from the versioned public contract with the pinned generator command shown below. Keeping the generator version fixed makes contract updates deliberate.

Configure requests

Run calls from a trusted server, read the access token from the environment, and use the base address and timeouts shown in the examples. Never place the token in browser code.

List pets

The Java, Python, and Node.js examples below perform the same first operation with standard platform libraries, so they do not depend on an unpublished package.

Handle errors

Check both the response status and body. Keep the request identifier when contacting support, but never log the access token. Retry a write or a diet generation only when the request can be repeated safely.

Version and source

Generate clients from the public OpenAPI bundle. Pin the contract and generator versions in your build so upgrades are reviewed and repeatable.

Java
curl --fail --silent --show-error https://api.barflab.io/openapi.yaml -o openapi.yaml
docker run --rm -v "$PWD:/local" openapitools/openapi-generator-cli:v7.24.0 generate \
  -i /local/openapi.yaml -g java -o /local/generated/barflab-java \
  --additional-properties=library=native
Java HTTP
var request = HttpRequest.newBuilder(URI.create(
    "https://api.barflab.io/v1/pets"))
  .header("Authorization", "Bearer " + System.getenv("BARFLAB_TOKEN"))
  .header("Accept", "application/json")
  .timeout(Duration.ofSeconds(30))
  .GET()
  .build();
var response = httpClient.send(request, BodyHandlers.ofString());
Python
curl --fail --silent --show-error https://api.barflab.io/openapi.yaml -o openapi.yaml
docker run --rm -v "$PWD:/local" openapitools/openapi-generator-cli:v7.24.0 generate \
  -i /local/openapi.yaml -g python -o /local/generated/barflab-python
Python HTTP
import os
import urllib.request

request = urllib.request.Request(
    "https://api.barflab.io/v1/pets",
    headers={
        "Authorization": f"Bearer {os.environ['BARFLAB_TOKEN']}",
        "Accept": "application/json",
    },
)
with urllib.request.urlopen(request, timeout=30) as response:
    body = response.read()
Node.js
curl --fail --silent --show-error https://api.barflab.io/openapi.yaml -o openapi.yaml
docker run --rm -v "$PWD:/local" openapitools/openapi-generator-cli:v7.24.0 generate \
  -i /local/openapi.yaml -g typescript-fetch -o /local/generated/barflab-node
Node.js HTTP
const response = await fetch(
  "https://api.barflab.io/v1/pets",
  {
    headers: {
      Authorization: `Bearer ${process.env.BARFLAB_TOKEN}`,
      Accept: "application/json",
    },
    signal: AbortSignal.timeout(30_000),
  },
);
const body = await response.json();
Operation ID
petsList