Closed picoHz closed 2 years ago
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) } }
I added a public Request initializer in 0.4.0.
Request
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?