{"modulePath":"github.com/benthosdev/benthos","version":"v0.26.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package api\n\nPackage api implements a type used for creating the Benthos HTTP API.\n\n## Types\n\n```go\ntype Config struct {\n\tAddress        string `json:\"address\" yaml:\"address\"`\n\tReadTimeoutMS  int    `json:\"read_timeout_ms\" yaml:\"read_timeout_ms\"`\n\tRootPath       string `json:\"root_path\" yaml:\"root_path\"`\n\tDebugEndpoints bool   `json:\"debug_endpoints\" yaml:\"debug_endpoints\"`\n}\n```\nConfig contains the configuration fields for the Benthos API.\n\n```go\nfunc NewConfig() Config\n```\nNewConfig creates a new API config with default values.\n\n```go\ntype Dynamic struct {\n\t// contains filtered or unexported fields\n}\n```\nDynamic is a type for exposing CRUD operations on dynamic broker configurations as an HTTP interface. Events can be registered for listening to configuration changes, and these events should be forwarded to the dynamic broker.\n\n```go\nfunc NewDynamic() *Dynamic\n```\nNewDynamic creates a new Dynamic API type.\n\n```go\nfunc (d *Dynamic) HandleCRUD(w http.ResponseWriter, r *http.Request)\n```\nHandleCRUD is an http.HandleFunc for performing CRUD operations on dynamic components by their ids.\n\n```go\nfunc (d *Dynamic) HandleList(w http.ResponseWriter, r *http.Request)\n```\nHandleList is an http.HandleFunc for returning maps of active dynamic components by their id to uptime.\n\n```go\nfunc (d *Dynamic) OnDelete(onDelete func(id string) error)\n```\nOnDelete registers a func to handle CRUD events where a request wants to remove a dynamic configuration. An error should be returned if the component failed to close.\n\n```go\nfunc (d *Dynamic) OnUpdate(onUpdate func(id string, conf []byte) error)\n```\nOnUpdate registers a func to handle CRUD events where a request wants to set a new value for a dynamic configuration. An error should be returned if the configuration is invalid or the component failed.\n\n```go\nfunc (d *Dynamic) Started(id string, config []byte)\n```\nStarted should be called whenever an active dynamic component has started with a new configuration. A normalised form of the configuration should be provided and will be delivered to clients that query the component contents.\n\n```go\nfunc (d *Dynamic) Stopped(id string)\n```\nStopped should be called whenever an active dynamic component has closed, whether by naturally winding down or from a request.\n\n```go\ntype Type struct {\n\t// contains filtered or unexported fields\n}\n```\nType implements the Benthos HTTP API.\n\n```go\nfunc New(\n\tversion string,\n\tdateBuilt string,\n\tconf Config,\n\twholeConf interface{},\n\tlog log.Modular,\n\tstats metrics.Type,\n) *Type\n```\nNew creates a new Benthos HTTP API.\n\n```go\nfunc (t *Type) ListenAndServe() error\n```\nListenAndServe launches the API and blocks until the server closes or fails.\n\n```go\nfunc (t *Type) RegisterEndpoint(path, desc string, handler http.HandlerFunc)\n```\nRegisterEndpoint registers a http.HandlerFunc under a path with a description that will be displayed under the /endpoints path.\n\n```go\nfunc (t *Type) Shutdown(ctx context.Context) error\n```\nShutdown attempts to close the http server.\n\n","path":"github.com/benthosdev/benthos/lib/api","name":"api","synopsis":"Package api implements a type used for creating the Benthos HTTP API.","isRedistributable":true}
