Quick Start
Build your first REST API
Humus REST services provide a complete framework for building OpenAPI-compliant HTTP APIs with automatic schema generation, type-safe handlers, and built-in observability.
REST services in Humus are built on:
package main
import (
"context"
"net/http"
"github.com/z5labs/humus/rest"
)
type Config struct {
rest.Config `config:",squash"`
}
type HelloResponse struct {
Message string `json:"message"`
}
func main() {
rest.Run(rest.YamlSource("config.yaml"), Init)
}
func Init(ctx context.Context, cfg Config) (*rest.Api, error) {
handler := rest.ProducerFunc[HelloResponse](func(ctx context.Context) (*HelloResponse, error) {
return &HelloResponse{Message: "Hello, World!"}, nil
})
api := rest.NewApi(
"Hello Service",
"1.0.0",
rest.Handle(
http.MethodGet,
rest.BasePath("/hello"),
rest.ProduceJson(handler),
),
)
return api, nil
}
The main API object that combines:
Type-safe handler abstraction in the rest package:
rest.Handler[Req, Resp] - Business logic interfaceFlexible path definition:
/users/users/{id}/users/{id}/posts/{postId}Every REST service automatically includes:
GET /openapi.json - OpenAPI 3.0 specificationGET /health/liveness - Liveness probeGET /health/readiness - Readiness probeThis section covers:
Start with the Quick Start Guide to build your first REST service.
Build your first REST API
Quick reference for REST handler helpers
JWT, API keys, and security
Paths and parameters
Operation-level request and response processing
Custom error responses and RFC 7807 Problem Details
Working with generated specs
Monitoring service health