Skip to content
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

Duplicating requests with different body #13

Closed
picoHz opened this issue Jan 8, 2022 · 1 comment
Closed

Duplicating requests with different body #13

picoHz opened this issue Jan 8, 2022 · 1 comment

Comments

@picoHz
Copy link

picoHz commented Jan 8, 2022

Hi. I want to make multiple requests whose parameters are identical except for their body.
Since requests can be created only by the factory methods, I have to write code like this to duplicate requests.
Is there a better way to handle this case?

func duplicate<Response: Decodable, Body: Encodable>(request: Request<Response>, body: Body) -> Request<Response> {
        switch request.method {
    case "post":
        return .post(request.path, query: request.query, body: body, headers: request.headers)
    case "put":
        return .put(request.path, query: request.query, body: body, headers: request.headers)
    case "delete":
        return .delete(request.path, query: request.query, body: body, headers: request.headers)
    default:
        return .get(request.path)
    }
}
@kean
Copy link
Owner

kean commented Jan 10, 2022

I added a public Request initializer in 0.4.0.

@kean kean closed this as completed Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants