Documentation
¶
Overview ¶
Package http is a sink destination that delivers payloads over HTTP using the standard library's net/http. It depends only on the standard library and crucible/sink — there is no third-party SDK dependency. Register a transformer that turns each payload type into a Post or PostJSON operation, then attach the result of New to a sink.Manifold.
Stability ¶
Experimental (pre-v1); the API may change until the suite locks v1.0.0.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New builds an Outlet that applies each payload's registered Op[Doer] to doer. The outlet is named "http" unless overridden with sink.WithName.
Example ¶
// SPDX-License-Identifier: Apache-2.0
package main
import (
"context"
"fmt"
"io"
gohttp "net/http"
"net/http/httptest"
csink "github.com/stablekernel/crucible/sink"
httpsink "github.com/stablekernel/crucible/sink/http"
)
type invoicePaid struct{ InvoiceID string }
func main() {
// Start a test server that records the request and responds 200 OK.
var received string
srv := httptest.NewServer(gohttp.HandlerFunc(func(w gohttp.ResponseWriter, r *gohttp.Request) {
body, _ := io.ReadAll(r.Body)
received = string(body)
w.WriteHeader(gohttp.StatusOK)
}))
defer srv.Close()
reg := httpsink.NewRegistry()
csink.Register(reg, func(_ context.Context, p invoicePaid) csink.Op[httpsink.Doer] {
return httpsink.Post(srv.URL+"/webhooks", "application/json", []byte(`{"invoice":"`+p.InvoiceID+`"}`))
})
outlet := httpsink.New(srv.Client(), reg)
_ = outlet.Sink(context.Background(), invoicePaid{InvoiceID: "INV-42"})
fmt.Println(received)
}
Output: {"invoice":"INV-42"}
func NewRegistry ¶
NewRegistry returns an empty registry of Op[Doer] for callers to populate with sink.Register.
Types ¶
type Doer ¶
Doer is the narrow net/http surface this destination needs. It is satisfied by *http.Client (the standard library's default client), so consumers can wire any *http.Client — custom timeouts, transports, or test servers — without this package importing anything beyond the standard library.