hclapi

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 7 Imported by: 0

README

hclapi

Go Reference Release CI

hclapi is a declarative API runtime powered by HCL.

Define HTTP routes, validation, SQL, Valkey, Starlark, Go callbacks, and OpenAPI documentation without generating application code.

Manifests are loaded, validated, and compiled at startup, then executed directly at request time.

Documentation · Examples

Example

server {
  host = "0.0.0.0"
  port = 8080
}

connection "sql" "main" {
  engine = "postgres"
  source = env("DATABASE_URL")
}

route "POST /users" {
  request {
    body {
      field "email" {
        type     = "string"
        format   = "email"
        required = true
      }

      field "name" {
        type     = "string"
        required = true
      }
    }
  }

  step "sql" "create" {
    connection = "main"

    query = <<-SQL
      INSERT INTO users (email, name)
      VALUES (@email, @name)
      RETURNING id, email, name
    SQL

    args = {
      email = ctx.request.body.email
      name  = ctx.request.body.name
    }
  }

  respond {
    status = 201
    body   = steps.create.row
  }
}

Go

hclapi is also embeddable:

config, err := hclapi.Load("routes/*.hcl")
if err != nil {
    log.Fatal(err)
}

engine, err := hclapi.New(config)
if err != nil {
    log.Fatal(err)
}
defer engine.Close()

http.ListenAndServe(":8080", engine)

Custom Go behavior can be registered with hclapi.WithStep. More information available in the Go integration guide.

Install

go install github.com/ju4n97/hclapi/cmd/hclapi@latest

Or use the release binaries and container images documented in the installation guide.

Documentation

See hclapi documentation.

Contributing

See CONTRIBUTING.md.

License

MIT

Documentation

Overview

Package hclapi provides an embeddable declarative API runtime powered by HCL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SQL added in v0.2.0

func SQL(e *Engine, name string) (*sql.DB, bool)

SQL retrieves an active *sql.DB connection pool by connection name.

func Valkey added in v0.2.0

func Valkey(e *Engine, name string) (valkey.Client, bool)

Valkey retrieves an active Valkey client by connection name.

Types

type Args added in v0.1.2

type Args = engine.Args

Args provides type-safe, generic argument extraction and coercion for Go steps.

type Config added in v0.2.0

type Config = config.Config

Config represents the verified runtime configuration.

func Load added in v0.2.0

func Load(patterns ...string) (*Config, error)

Load discovers, compiles, and validates manifests from files, directories, or globs.

func Parse added in v0.2.0

func Parse(source string) (*Config, error)

Parse compiles an in-memory HCL manifest string into a verified Config.

type Engine

type Engine = engine.Engine

Engine handles routing, connection pooling, and pipeline execution.

func New added in v0.1.3

func New(cfg *Config, opts ...Option) (*Engine, error)

New initializes an executable Engine from a verified Config.

type Option added in v0.2.0

type Option = engine.Option

Option configures an Engine instance.

func WithLogger added in v0.2.0

func WithLogger(logger *slog.Logger) Option

WithLogger sets the structured logger for the engine.

func WithStep added in v0.2.0

func WithStep(name string, handler StepHandler) Option

WithStep registers a named Go step handler available to "go" steps.

func WithValkey added in v0.2.0

func WithValkey(name string, client valkey.Client) Option

WithValkey registers a pre-configured Valkey client for custom connection management.

type Problem added in v0.1.2

type Problem = problem.Problem

Problem represents an RFC 9457 Problem Details error payload.

type Step added in v0.1.2

type Step = engine.Step

Step holds execution parameters and HTTP request context for Go callbacks.

type StepHandler

type StepHandler = engine.StepHandler

StepHandler defines custom Go step functions.

Directories

Path Synopsis
cmd
hclapi command
examples
05_go_embedded command
internal
config
Package config defines the verified runtime models and enum types for the hclapi engine.
Package config defines the verified runtime models and enum types for the hclapi engine.
ctyconv
Package ctyconv converts Go runtime values to cty.Value and evaluates HCL expressions.
Package ctyconv converts Go runtime values to cty.Value and evaluates HCL expressions.
manifest
Package manifest discovers, parses, validates, and compiles HCL configuration files.
Package manifest discovers, parses, validates, and compiles HCL configuration files.
problem
Package problem implements RFC 9457 Problem Details for HTTP APIs.
Package problem implements RFC 9457 Problem Details for HTTP APIs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL