-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative interface #1
Comments
Builder pattern
like gentleman, gorequesterr := a.client.Post(ctx, "/api/contents").
JSON(in).
When(hx.Any(hx.IsServerError(), hx.IsNetworkError()), retry.With(bo)).
WhenOK(hx.AsJSON(&out)).
WhenNotOK(hx.AsError()).
Do() like restyerr := a.client.Request().
JSON(in).
When(hx.Any(hx.IsServerError(), hx.IsNetworkError()), retry.With(bo)).
WhenOK(hx.AsJSON(&out)).
WhenNotOK(hx.AsError()).
Post(ctx, "/api/contents") Builder pattern + Functional option patternerr := a.client.Post(ctx, "/api/contents").
Do(
hx.JSON(in),
hx.When(hx.Any(hx.IsServerError(), hx.IsNetworkError()), retry.With(bo)),
hx.WhenOK(hx.AsJSON(&out)),
hx.WhenNotOK(hx.AsError()),
) |
Path parameter supportlike gentleman/url, resty.Request.SetPathParamserr := a.client.Get(ctx, "/api/contents/{id}",
hx.Param("id", 1),
hx.WhenOK(hx.AsJSON(&out)),
hx.WhenNotOK(hx.AsError()),
) Builder pattern + Variadic parametererr := a.client.Get(ctx, "api", "contents", 1).
WhenOK(hx.AsJSON(&out)).
WhenNotOK(hx.AsError()).
Do() Helpererr := a.client.Get(ctx, hx.Path("api", "contents", 1),
hx.WhenOK(hx.AsJSON(&out)),
hx.WhenNotOK(hx.AsError()),
) |
Case study: Conditionally changing configurationsBuilder pattern: (In case of resty-like I/F) client := a.client.Request().
JSON(in).
WhenOK(hx.AsJSON(&out)).
WhenNotOK(hx.AsError())
if appEnv == "production" {
client = client.When(hx.Any(hx.IsServerError(), hx.IsNetworkError()), retry.With(bo))
}
err := client.Post(ctx, "/api/contents") Functional options pattern: options := []hx.Option{
hx.JSON(in),
hx.WhenOK(hx.AsJSON(&out)),
hx.WhenNotOK(hx.AsError())
}
if appEnv == "production" {
options = append(options, retry.When(hx.Any(hx.IsServerError(), hx.IsNetworkError()), newBackOff))
}
err := a.client.Post(ctx, "/api/contents", options...) |
Conditionally changing configurations with
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current(Everything as Option)
The text was updated successfully, but these errors were encountered: