{"action":"created","issue":{"url":"https://api.github.com/repos/Moya/Moya/issues/861","repository_url":"https://api.github.com/repos/Moya/Moya","labels_url":"https://api.github.com/repos/Moya/Moya/issues/861/labels{/name}","comments_url":"https://api.github.com/repos/Moya/Moya/issues/861/comments","events_url":"https://api.github.com/repos/Moya/Moya/issues/861/events","html_url":"https://github.com/Moya/Moya/pull/861","id":197476357,"number":861,"title":"Default TargetType Property Implementations And SingleURLTarget","user":{"login":"scottrhoyt","id":4259250,"avatar_url":"https://avatars.githubusercontent.com/u/4259250?v=3","gravatar_id":"","url":"https://api.github.com/users/scottrhoyt","html_url":"https://github.com/scottrhoyt","followers_url":"https://api.github.com/users/scottrhoyt/followers","following_url":"https://api.github.com/users/scottrhoyt/following{/other_user}","gists_url":"https://api.github.com/users/scottrhoyt/gists{/gist_id}","starred_url":"https://api.github.com/users/scottrhoyt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottrhoyt/subscriptions","organizations_url":"https://api.github.com/users/scottrhoyt/orgs","repos_url":"https://api.github.com/users/scottrhoyt/repos","events_url":"https://api.github.com/users/scottrhoyt/events{/privacy}","received_events_url":"https://api.github.com/users/scottrhoyt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":25,"created_at":"2016-12-24T20:24:43Z","updated_at":"2016-12-31T21:49:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Moya/Moya/pulls/861","html_url":"https://github.com/Moya/Moya/pull/861","diff_url":"https://github.com/Moya/Moya/pull/861.diff","patch_url":"https://github.com/Moya/Moya/pull/861.patch"},"body":"Not 100% sure this is a great idea, but hopefully this PR can facilitate a discussion. I'll add a CHANGELOG entry and update the docs if we agree on this direction.\r\n\r\n## Default `TargetType` Property Implementations And `SingleURLTarget`\r\n\r\n### Problem\r\n\r\nCurrently, if a Moya user wants to make a simple GET request to a new URL (not represented by an existing `TargetType`) they have a couple of options: \r\n\r\nThey can create a new `TargetType` which will allow them to keep a consistent networking layer as well as have access to `RxMoyaProvider`, `ReactiveMoyaProvider`, easy response mapping, and 3rd party extensions. However, there is a good amount of boilerplate needed for a simple request and a new type needs to be created even for one-off requests.\r\n\r\nAlternatively, they could utilize `Alamofire` or `URLSession` directly, but this would introduce inconsistency into their networking layer and they wouldn't have access to easy reactive extensions and response mapping.\r\n\r\n### Solution\r\n\r\nProvide default implementations of all `TargetType` properties to represent the most commonly used combination of request settings: a GET request with no parameters.\r\n\r\nAdditionally, provide a trivial `TargetType` implementation (`SingleURLTarget`) so that users can easily create a `TargetType` that represents a GET request to a single URL with no parameters.\r\n\r\n### Usage\r\n\r\n```swift\r\nlet url = URL(string: \"http://api.com\")!\r\n\r\n// Example 1\r\nMoyaProvider().request(SingleURLTarget(url: url)) {\r\n    result in\r\n    // process result\r\n}\r\n\r\n// Example 2\r\nlet target = SingleURLTarget(url: url)\r\nMoyaProvider().request(target) {\r\n    result in\r\n    // process result\r\n}\r\n\r\n// Example 3\r\nlet provider = MoyaProvider<SingleURLTarget>()\r\nprovider.request(target) {\r\n    result in\r\n    // process result\r\n}\r\n```\r\n\r\n### Tradeoffs\r\n\r\n* A reduction in conformance errors that are generated in compilation. These errors are often a source of documentation of available behavior.\r\n* Explicit implementation of all behavior is self documenting and may be easier for developers to reason about.\r\n\r\nThese tradeoffs can be mitigated by improving the documentation for `TargetType`.\r\n\r\n### Alternatives Considered\r\n\r\nProvide `SingleURLTarget` without providing default implementations for other `TargetType`s. This would be a good compromise between servicing the specific use case of a simple target without reducing the self-documenting nature of implementing `TargetType`. However, there are other common use cases where other properties like `parameters`, `method`, `task`, or `sampleData` can result in unnecessary boilerplate."},"comment":{"url":"https://api.github.com/repos/Moya/Moya/issues/comments/269883062","html_url":"https://github.com/Moya/Moya/pull/861#issuecomment-269883062","issue_url":"https://api.github.com/repos/Moya/Moya/issues/861","id":269883062,"user":{"login":"scottrhoyt","id":4259250,"avatar_url":"https://avatars.githubusercontent.com/u/4259250?v=3","gravatar_id":"","url":"https://api.github.com/users/scottrhoyt","html_url":"https://github.com/scottrhoyt","followers_url":"https://api.github.com/users/scottrhoyt/followers","following_url":"https://api.github.com/users/scottrhoyt/following{/other_user}","gists_url":"https://api.github.com/users/scottrhoyt/gists{/gist_id}","starred_url":"https://api.github.com/users/scottrhoyt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottrhoyt/subscriptions","organizations_url":"https://api.github.com/users/scottrhoyt/orgs","repos_url":"https://api.github.com/users/scottrhoyt/repos","events_url":"https://api.github.com/users/scottrhoyt/events{/privacy}","received_events_url":"https://api.github.com/users/scottrhoyt/received_events","type":"User","site_admin":false},"created_at":"2016-12-31T21:49:22Z","updated_at":"2016-12-31T21:49:22Z","body":"Alright. I'm going to leave this PR open for the moment so that others that might be gone for the holidays can consider it when they get back. It can still be done post 8.0.0 since it won't be a breaking change. \r\n\r\nI think we can make the case for providing a default for `validate` since it's suppressing Alamofire behavior and we try to not leak Alamofire where possible. However, I'll open a PR to remove the default for `parameterEncoding` and include that default in this PR. That way we are consistent on the current approach and can decide on providing defaults for `TargetType` as a whole."}}
{"actor":{"display_login":"scottrhoyt"}}