Skip to content

HookFreight/hookfreight-go

Repository files navigation

hookfreight-go

Official Go SDK for Hookfreight.

Capture, inspect, replay, and reliably deliver webhooks with full visibility.

Installation

go get github.com/hookfreight/hookfreight-go

Quick Start

Hookfreight Cloud

package main

import (
    "context"
    "fmt"

    hookfreight "github.com/hookfreight/hookfreight-go"
)

func main() {
    hf := hookfreight.NewClient(hookfreight.Config{APIKey: "hf_sk_..."})

    result, err := hf.Deliveries.List(context.Background(), &hookfreight.ListDeliveriesParams{
        PaginationParams: hookfreight.PaginationParams{Limit: 10},
    })
    if err != nil {
        panic(err)
    }

    fmt.Println(result.Deliveries)
}

Self-Hosted

hf := hookfreight.NewClient(hookfreight.Config{
    BaseURL: "http://localhost:3030/api/v1",
})

Configuration

Option Type Default Description
APIKey string API key for Hookfreight Cloud. Optional for self-hosted.
BaseURL string https://api.hookfreight.com/v1 Base URL of the API. Override for self-hosted.
Timeout time.Duration 30s Request timeout.
HTTPClient HTTPDoer http.Client Optional custom HTTP client.

Usage

ctx := context.Background()

app, _ := hf.Apps.Create(ctx, hookfreight.CreateAppParams{Name: "My App"})
endpoint, _ := hf.Endpoints.Create(ctx, hookfreight.CreateEndpointParams{
    Name:       "Stripe",
    AppID:      app.ID,
    ForwardURL: "https://example.com/webhooks/stripe",
})

_, _ = hf.Events.Get(ctx, "evt_...")
stats, _ := hf.Deliveries.QueueStats(ctx)
fmt.Println(stats)

_, _ = hf.Endpoints.Delete(ctx, endpoint.ID)
_, _ = hf.Apps.Delete(ctx, app.ID)

Error Handling

_, err := hf.Apps.Get(ctx, "app_nonexistent")
if err != nil {
    var notFound *hookfreight.NotFoundError
    if errors.As(err, &notFound) {
        fmt.Println("App not found")
    }
}

Examples

  • examples/basic_usage/main.go
  • examples/manage_endpoints/main.go
  • examples/retry_failed_deliveries/main.go
  • examples/monitor_queue/main.go

License

Apache-2.0

Packages

 
 
 

Contributors

Languages