Skip to content
Get started
Bastionary › Knowledge base › Getting started

Call the Bastionary API from Next.js, React, Python and Go

By Bastionary · Getting started

Bastionary exposes every capability through one endpoint, POST /api/v1/execute, so you do not need an SDK. Each example below validates a license key against your own Bastionary server. Replace https://auth.example.com with the address of your server.

Next.js (App Router)

Call Bastionary from a server-side route handler so keys and machine fingerprints never reach the browser.

import { NextResponse } from 'next/server';

export async function GET() {
  const response = await fetch('https://auth.example.com/api/v1/execute', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      command: 'LICENSE.VALIDATE',
      params: { key: '<LICENSE_KEY>', machine_fingerprint: '<MACHINE_FINGERPRINT>' },
    }),
  });
  const result = await response.json();
  return NextResponse.json({ valid: result.data.valid });
}

result.data.valid is true when the license is active. Handle both cases in your UI.

React

Install the JavaScript SDK with npm install @bastionary/sdk, point a client at your server and call validateLicense() inside an effect.

import { useState, useEffect } from 'react';
import { BastionClient } from '@bastionary/sdk';

export default function LicenseStatus() {
  const [valid, setValid] = useState(null);
  useEffect(() => {
    const client = new BastionClient('https://auth.example.com');
    client.validateLicense('LICENSE_KEY', 'MACHINE_FINGERPRINT').then(res => setValid(res.data.valid));
  }, []);
  if (valid === null) return <div>Checking...</div>;
  return valid ? <div>Licensed</div> : <div>Not licensed</div>;
}

Python (FastAPI)

Install the dependencies with pip install fastapi httpx and post the command with an async client.

import httpx
from fastapi import FastAPI

app = FastAPI()

@app.get("/license/{key}")
async def check_license(key: str):
    async with httpx.AsyncClient() as client:
        resp = await client.post(
            "https://auth.example.com/api/v1/execute",
            json={"command": "LICENSE.VALIDATE", "params": {"key": key}},
        )
    return {"valid": resp.json()["data"]["valid"]}

Go

The standard library is all you need.

package main

import (
    "bytes"
    "encoding/json"
    "net/http"
)

type Response struct {
    Data struct {
        Valid bool `json:"valid"`
    } `json:"data"`
}

func ValidateLicense(key string) (bool, error) {
    payload := map[string]interface{}{
        "command": "LICENSE.VALIDATE",
        "params":  map[string]string{"key": key},
    }
    b, err := json.Marshal(payload)
    if err != nil {
        return false, err
    }
    r, err := http.Post("https://auth.example.com/api/v1/execute", "application/json", bytes.NewReader(b))
    if err != nil {
        return false, err
    }
    defer r.Body.Close()
    var result Response
    if err := json.NewDecoder(r.Body).Decode(&result); err != nil {
        return false, err
    }
    return result.Data.Valid, nil
}

Next steps

Run it yourself

Bastionary is free, open-source software. Follow the quick start to have it running on your own server, or browse the releases on Git.

Get started