TABResourceLoader
TABResourceLoader copied to clipboard
Should network requests which aren't GET require data to be returned
It's a pretty common pattern to just use status codes for some of the HTTP methods. For example, I want to send a push notification token to my server. I don't care about the response other than if it's a 200
or not as it's quite fire-and-forget.
My understanding of the current Resource Loader implementation is that we need to return and parse some data even on POST
etc.
What do people think?
We could add a protocol extension for the DataResourceType
when the Model is Void to return .success()
by default to eliminate this step for the developer as this is common on most non GET
requests
If you don't care about the data you can make the Model
on the resource be Void
and implement the DataResourceType
to always return .success()
.
@Neil3079 I don't think we should add a default implementation since it's nice to have the compiler error when the method is not implemented. This case is only relevant when the Model
is Void
.
@lucianomarisi Well we would still have the compiler error as the extension would only be on the case when the Model is Void
?
ahh yes, makes sense, we could add something like this:
extension DataResourceType where Model == Void {
func model(from data: Data) throws -> Model {
return Void()
}
}
Not sure if the syntax is correct.
I seem to remember in Swift Void
is just the empty Tuple type ()
You're correct, trying a bit of code in Xcode, this seems to work:
public extension DataResourceType where Model == Void {
func model(from data: Data) throws {}
}
This would be the defined resource:
struct VoidResource: DataResourceType {
typealias Model = Void
}