You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to suggest some features about resty middleware.
give both resty.Request, resty.Response to parameter of middleware
currently, middleware only can have a resty.Request or a resty.Response as a parameter.
I know we don't have response before we send request.
but it's only a data type that we can make an empty or default value.
setting resty.Response and return by middleware
if we can have resty.Response on request middleware, we can change the resty.Response value directly
As resty.Response has already been set up, It's possible to return without error before sending request
I think this changing will make middleware more powerful
caching middleware will be a good example of it.
an empty response without error will be problematic so developer should be aware of it
but I think this bug would be easily catched by developer who use this feature.
example
// Create a Resty Client
client := resty.New()
// Registering Request Middleware
client.OnBeforeRequest(func(c *resty.Client, req *resty.Request, resp *resty.Response) error {
// Now you have access to Client and current Request and response object
// manipulate it as per your need
var data struct{
Foo string `json:"foo"`
Bar string `json:"bar"`
}{
Foo: "a",
Bar: "b",
}
// should make some functions to resty.Response
resp.SetBody(data)
resp.Stop()
return nil // if its success otherwise return error
})
// Registering Response Middleware
client.OnAfterResponse(func(c *resty.Client, req *resty.Request, resp *resty.Response) error {
// Now you have access to Client and current Request and Response object
// manipulate it as per your need
return nil // if its success otherwise return error
})
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I would like to suggest some features about resty middleware.
give both resty.Request, resty.Response to parameter of middleware
currently, middleware only can have a resty.Request or a resty.Response as a parameter.
I know we don't have response before we send request.
but it's only a data type that we can make an empty or default value.
setting resty.Response and return by middleware
if we can have resty.Response on request middleware, we can change the resty.Response value directly
As resty.Response has already been set up, It's possible to return without error before sending request
I think this changing will make middleware more powerful
caching middleware will be a good example of it.
an empty response without error will be problematic so developer should be aware of it
but I think this bug would be easily catched by developer who use this feature.
example
Beta Was this translation helpful? Give feedback.
All reactions