-
Notifications
You must be signed in to change notification settings - Fork 49
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
Add HTTPClient for Web API Client Library #64
Conversation
Sources/HTTPClient/HTTPClient.swift
Outdated
|
||
public protocol HTTPClientProtocol { | ||
associatedtype Body | ||
associatedtype Data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add associatedType Body, Data for Data
, ByteBuffer
, [Int8]
.
#15 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having associated types here is kinda defeating the purpose of having a general protocol level abstraction for an HTTP client. In my opinion, we should come up with standardised types for the type of data.
Furthermore, I see two more outstanding questions:
- We should support optional trailers on both the request and response side
- We should support bi-direction body streaming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we adopt 1 or 2?
- one associatedType(Data), data, body has same Type.
- no associatedType, use Foundation.Data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should adopt any of the two. There is currently no "bag-of-bytes" currency type that is used across the ecosystems. Choosing either Data
or ByteBuffer
will come with downsides.
In my opinion, we have to solve this question in the standard library first before we can tackle providing a common API abstraction here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we adopt Foundation.Data without waiting for the issue to be resolved?
I think solving the standard library issue is difficult and will take too much time.
Does Apple/SwiftLang have any plans to resolve this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we adopt Foundation.Data without waiting for the issue to be resolved?
We can't adopt Foundation.Data
across the ecosystem right now since the server ecosystem uses ByteBuffer
and is built around that. Adopting Foundation.Data
would incur unnecessary allocations at the API boundaries to bridge between the types.
Does Apple/SwiftLang have any plans to resolve this?
There were previous discussions around this topic but there currently is no proposed solution. One of the focus areas of the Swift project right now is tackling ownership and lifetime in the standard library including in collections like Array<UInt8>
. This might inform some of the next steps around a common bag-of-bytes type.
Sadly, I think this puts the proposal with creating a shared API abstraction for HTTP clients on hold right now. Until we can solve the bag-of-bytes problem at the language level. Now you can still create this protocol in your own code and conform the various clients to it.
add HTTPClientFoundation combining Body and Data into one associatedtype. remove associatedType
e146f50
to
f0d99d1
Compare
HTTPClient
Web API Client Library needs
HTTPClient
forURLSession
,SwiftNIO
...Example: GitHub API Client Library