Configuration
RespKit's package-level helpers use a default engine, so basic responses work without setup.
Create a dedicated engine
Use resp.New to give an API its own policy or to avoid changing the process-wide default:
api, err := resp.New(
resp.WithNaming(resp.CamelCase),
resp.WithDefaultLocale("en"),
resp.WithErrorFormat(resp.ProblemDetails),
)
if err != nil {
return err
}
return api.OK(ctx, data)An engine is immutable after creation and safe for concurrent use. Available naming options are resp.SnakeCase, resp.CamelCase, and resp.PascalCase. Error formats are resp.Envelope and resp.ProblemDetails.
Configure the default engine
resp.Configure replaces the process-wide default engine atomically:
if err := resp.Configure(resp.WithDefaultLocale("en")); err != nil {
log.Fatal(err)
}Call it once during application startup, before handlers serve requests. In tests, prefer a dedicated engine so tests do not affect one another through shared global configuration.
Per-response options
resp.Locale("en") and resp.Location("/users/123") apply only to the response call that receives them. The location option sets the Location header on a 201 Created response.
The option to expose internal error messages is available only when creating an engine. It cannot be set for an individual request or through a request header. See security guidance before considering it for isolated local development.
Error handling
resp.New and resp.Configure return an error when options are invalid, such as when the configured default locale has no translation catalog. Handle configuration errors at startup so the application does not begin serving with an unintended policy.
