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

Should network requests which aren't GET require data to be returned #40

Open
jonhocking opened this issue Feb 28, 2017 · 8 comments
Open
Labels

Comments

@jonhocking
Copy link
Contributor

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?

@Neil3079
Copy link

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

@lucianomarisi
Copy link
Contributor

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().

@lucianomarisi
Copy link
Contributor

@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.

@Neil3079
Copy link

Neil3079 commented Feb 28, 2017

@lucianomarisi Well we would still have the compiler error as the extension would only be on the case when the Model is Void?

@lucianomarisi
Copy link
Contributor

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.

@Neil3079
Copy link

Neil3079 commented Feb 28, 2017

I seem to remember in Swift Void is just the empty Tuple type ()

@lucianomarisi
Copy link
Contributor

lucianomarisi commented Feb 28, 2017

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
}

@KaneCheshire
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants