You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 30, 2025. It is now read-only.
@@ -26,47 +26,32 @@ As for Spotify, we wanted a light networking library that we had full control ov
26
26
-**The User level**, which controls the authentication of the HTTP requests.
27
27
-**The View level**, which allows automatic cancellation of requests the view has made upon deallocation.
28
28
29
-
### Authentication:key:
29
+
### Authentication
30
30
The authentication in this case is abstract, allowing the creator of the SPTDataLoaderFactory to define their own semantics for token acquisition and injection. It allows for asynchronous token acquisition if the token is invalid that seamlessly integrates with the HTTP request-response pattern.
31
31
32
-
### Back-off policy:cop:
32
+
### Back-off policy
33
33
The data loader service allows rate limiting of URLs to be set explicitly or to be determined by the server using the “Retry-After” semantic. It allows back-off retrying by using a jittered exponential backoff to prevent the thundering hordes creating a request storm after a predictable exponential period has expired.
34
34
35
-
## Installation
36
-
SPTDataLoader can be installed in a variety of ways including traditional static libraries and dynamic frameworks. As well as using either of the dependency managers CocoaPods and Carthage.
35
+
## Installation:building_construction:
36
+
SPTDataLoader can be installed in a variety of ways, either as a dynamic framework, a static library, or through a dependency manager such as CocoaPods or Carthage.
37
37
38
-
### Static Library
39
-
Simply include `SPTDataLoader.xcodeproj` in your App’s Xcode project, and link your app with the library in the “Build Phases” section.
38
+
### Manually
39
+
#### Dynamic Framework
40
+
Drag the [framework](https://github.com/spotify/SPTDataLoader/releases) into the “Frameworks, Libraries, and Embedded Content” area in the “General” section of the target.
41
+
#### Static Library
42
+
Drag `SPTDataLoader.xcodeproj` into your App’s Xcode project and link your app with the library in the “Build Phases” section of the target.
40
43
41
44
### CocoaPods
42
-
We are indexed on [CocoaPods](http://cocoapods.org), which can be installed using [Ruby gems](https://rubygems.org/):
43
-
```shell
44
-
$ gem install cocoapods
45
-
```
46
-
Then simply add `SPTDataLoader` to your `Podfile`.
47
-
```
48
-
pod 'SPTDataLoader', '~> 1.1'
49
-
```
50
-
Lastly let CocoaPods do it thing by running:
51
-
```shell
52
-
$ pod update
45
+
To integrate SPTDataLoader into your project using [CocoaPods](http://cocoapods.org), add it to your `Podfile`:
46
+
```ruby
47
+
pod 'SPTDataLoader', '~> 2.1'
53
48
```
54
49
55
50
### Carthage
56
-
We support [Carthage](https://github.com/Carthage/Carthage) and provide pre-built binary frameworks for all new releases. Start by making sure you have the latest version of Carthage installed, e.g. using [Homebrew](http://brew.sh/):
57
-
```shell
58
-
$ brew update
59
-
$ brew install carthage
60
-
```
61
-
You will also need to add `SPTDataLoader` to your `Cartfile`:
51
+
To integrate SPTDataLoader into your project using [Carthage](https://github.com/Carthage/Carthage), add it to your `Cartfile`:
52
+
```ogdl
53
+
github "spotify/SPTDataLoader" ~> 2.1
62
54
```
63
-
github "spotify/SPTDataLoader" ~> 1.1
64
-
```
65
-
After that is all said and done, let Carthage pull in SPTDataLoader like so:
66
-
```shell
67
-
$ carthage update
68
-
```
69
-
Next up, you need to add the framework to the Xcode project of your App. Lastly link the framework with your App and copy it to the App’s Frameworks directory under the “Build Phases”.
70
55
71
56
## Usage example :eyes:
72
57
For an example of this framework's usage, see the demo application `SPTDataLoaderDemo` in `SPTDataLoader.xcodeproj`. Just follow the instructions in [`ClientKeys.h`](demo/ClientKeys.h).
@@ -255,36 +240,63 @@ The SPTDataLoader architecture is designed to centralise authentication around t
255
240
```
256
241
As you can see all we are doing here is playing with the headers. It should be noted that if you receive an authoriseRequest: call the rest of the request will not execute until you have either sent the delegate a signal telling it the request has been authorised or failed to be authorised.
257
242
258
-
## Background story :book:
259
-
At Spotify we have begun moving to a decentralised HTTP architecture, and in doing so have had some growing pains. Initially we had a data loader that would attempt to refresh the access token whenever it became invalid, but we immediately learned this was very hard to keep track of. We needed some way of injecting this authorisation data automatically into a HTTP request that didn't require our features to do any more heavy lifting than they were currently doing.
243
+
### Swift overlay
244
+
Additional APIs that enhance usage within Swift applications are available through the `SPTDataLoaderSwift` library.
245
+
```swift
246
+
// Creating a DataLoader instance
247
+
let dataLoader = dataLoaderFactory.makeDataLoader(/* optional */responseQueue: myCustomQueue)
260
248
261
-
Thus we came up with a way to elegantly inject tokens in a Just-in-time manner for requests that require them. We also wanted to learn from our mistakes with our proprietary protocol, and bake in back-off policies early to avoid us DDOSing our own backends with huge amounts of eronious requests.
249
+
// Creating a Request instance -- all functions can be chained
250
+
let request = dataLoader.request(modelURL, sourceIdentifier: "model-page")
262
251
263
-
### Why no block interface?
264
-
We had some block interfaces on our proprietary protocol library, and what we noticed was that it was easy to miss the weakification of the variables used in the blocks, which caused view models to be held around in memory far longer than they should have been.
265
-
Another problem was whether we should use one block or multiple blocks for failures/successes, and what we learned from our old API was that developers could tend to miss failure states from a single block interface (e.g. handle an NSError passed in). Good examples of are animation blocks on UIView that do not take into account the failed BOOL passed in. This makes it necessary to use multiple blocks, however we wanted a contract where the developer was guaranteed to get a callback from the data loader on any of its ending states (even if they put in a nil to the request blocks). The way we achieved this was the use of the delegate pattern.
266
-
Unfortunately the block pattern is useful in a number of different scenarios, however it is far from our main use case at Spotify. To support this we would like to point out that someone can give the userInfo of a request a block and then call that block on the delegate callback if they were so inclined (we have one or two examples of this on our codebase).
let modelSerializer = ProtobufResponseSerializer<MyCustomModel>()
291
+
request.responseSerializable(serializer: modelSerializer) { response in
292
+
modelResultHandler(response.result)
293
+
}
294
+
```
295
+
296
+
## Background story :book:
297
+
At Spotify we have begun moving to a decentralised HTTP architecture, and in doing so have had some growing pains. Initially we had a data loader that would attempt to refresh the access token whenever it became invalid, but we immediately learned this was very hard to keep track of. We needed some way of injecting this authorisation data automatically into a HTTP request that didn't require our features to do any more heavy lifting than they were currently doing.
298
+
299
+
Thus we came up with a way to elegantly inject tokens in a Just-in-time manner for requests that require them. We also wanted to learn from our mistakes with our proprietary protocol, and bake in back-off policies early to avoid us DDOSing our own backends with huge amounts of eronious requests.
288
300
289
301
## Documentation :books:
290
302
See the [`SPTDataLoader` documentation](http://cocoadocs.org/docsets/SPTDataLoader) on [CocoaDocs.org](http://cocoadocs.org) for the full documentation.
0 commit comments