Closed kean closed 2 years ago
Just a few questions but 👍 for everything moving forward!
prevent "GET" requests from being sent with an HTTP body which is not allowed by the spec
My understanding of RFC 7231 is that GET
requests can have a body but should be ignored.
My understanding of RFC 7231 is that
GET
requests can have a body but should be ignored.
URLSession
immediately fails the requests with a body.
2022-08-18 07:49:19.795866-0400 xctest[99043:11389881] GET method must not have a body 2022-08-18 07:49:19.797580-0400 xctest[99043:11389879] Task <15BA91AD-79A2-48C4-BCC2-29F19BDE12D2>.<1> finished with error [-1103] Error Domain=NSURLErrorDomain Code=-1103 "resource exceeds maximum size" UserInfo={NSLocalizedDescription=resource exceeds maximum size, NSErrorFailingURLStringKey=https://api.github.com/user, NSErrorFailingURLKey=https://api.github.com/user, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <15BA91AD-79A2-48C4-BCC2-29F19BDE12D2>.<1>" ), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <15BA91AD-79A2-48C4-BCC2-29F19BDE12D2>.<1>, NSUnderlyingError=0x600000c60570 {Error Domain=kCFErrorDomainCFNetwork Code=-1103 "(null)"}}
I'm not sure what's the reasoning. I'm assuming it's caching. URLs must uniquely identify the resources.
This MR addresses multiple design issues with the
Request
type in Get 1.0.1. Add support for both
URL
andString
In Get 1.0, request can only be initialized with a
String
that represents either a relative URL (path) or an absolute one.This doesn't match the convention used on Apple platforms where URLs are usually represented using
URL
type. Get 2.0 now has two separate initializer:2. Deprecate telescoping factory methods
Having a separate factory method per HTTP method is not elegant. Initially it was designed this way to prevent "GET" requests from being sent with an HTTP body which is not allowed by the spec and by
URLSession
. But since theRequest
type also has a public initializer without this check, it doesn't make much sense to only have it in one place.The factory methods are deprecated in Get 2.0 and there is also a new
HTTPMethod
type.This is more verbose than writing
.post("/user")
, but I think it's a non-issue, and the clarify should be the priority.3. Change the order of parameters
Previously,
method
was the first parameter, but it had a default value. The first parameter should not have the default value.4. Response type defaulting to
Void
In Get 1.0, there were actually not one, but two sets of factory methods (see p2). In the second set, the default response type (
Request<Response>
) was set toVoid
. It allows the user to avoid explicitly specifying the response type when it'sVoid
. But the initializer for the same type was missing, and Get 2.0 introduces it, so you can now write this:Rejected
The
Request
initializer has a lot of parameters and it can be cumbersome to use. I considered adding some convenience methods for creating the requests, for example:While it's nice to have, I don't think it belongs in the framework. You can achieve the same with simple mutable structs in Swift and the users can add convenience extensions "aftermarket":