ComposableRequest
ComposableRequest is a networking layer based on a declarative interface, written in (modern) Swift.
It abstracts away URLSession
implementation (or your preferred custom networking library), in order to provide concise and powerful endpoint representations, supporting, out-of-the-box, completion handlers, Combine Publisher
s and structured concurrencty (async
/await
) with a single definition.
It comes with Storage
(inside of Storage), a way of caching Storable
items, and related concrete implementations (e.g. UserDefaultsStorage
, KeychainStorage
– for which you're gonna need to add StorageCrypto, depending on KeychainAccess, together with the ability to provide the final user of your API wrapper to inject code through Provider
s.
Status
You can find all changelogs directly under every release.
What's next?
ComposableRequest was initially Swiftagram's networking layer and it still tends to follow roughly the same development cycle.
Milestones, issues, are the best way to keep updated with active developement.
Feel free to contribute by sending a pull request.
Just remember to refer to our guidelines and Code of Conduct beforehand.
Installation
Swift Package Manager (Xcode 11 and above)
- Select
File
/Swift Packages
/Add Package Dependency…
from the menu. - Paste
https://github.com/sbertix/ComposableRequest.git
. - Follow the steps.
- Add Storage together with Requests for the full experience.
Why not CocoaPods, or Carthage, or ~blank~?
Supporting multiple dependency managers makes maintaining a library exponentially more complicated and time consuming.
Furthermore, with the integration of the Swift Package Manager in Xcode 11 and greater, we expect the need for alternative solutions to fade quickly.
Targets
- Requests, an HTTP client originally integrated in Swiftagram, the core library.
- Storage
- StorageCrypto, depending on KeychainAccess, can be imported together with Storage to extend its functionality.
Usage
Check out Swiftagram or visit the (auto-generated) documentation for Requests, Storage and StorageCrypto to learn about use cases.
Endpoint
As an implementation example, we can display some code related to the Instagram endpoint tasked with deleting a post.
How can the user then retreieve the information?
All the user has to do is…
Resume and cancel requests
What about cancelling the request, or starting it a later date?
Concrete implementation of Receivable
might implement suspension and cancellation through their underlying types (like URLSessionDataTask
or Cancellable
).
Caching
Caching of Storable
s is provided through conformance to the Storage
protocol, specifically by implementing either ThrowingStorage
or NonThrowingStorage
.
The library comes with several concrete implementations.
TransientStorage
should be used when no caching is necessary, and it's whatAuthenticator
s default to when noStorage
is provided.UserDefaultsStorage
allows for faster, out-of-the-box, testing, although it's not recommended for production as private cookies are not encrypted.KeychainStorage
, requiring you to add ComposableStorageCrypto, (preferred) stores them safely in the user's keychain.
-->