diff --git a/README.md b/README.md index 87e490a..4a6013c 100644 --- a/README.md +++ b/README.md @@ -9,113 +9,9 @@ [![Twitter](https://img.shields.io/badge/Twitter-%40lashraf96-blue)](https://twitter.com/lashraf96) [![LinkedIn](https://img.shields.io/badge/LinkedIn-loay--ashraf-blue)](https://linkedin.com/in/loay-ashraf) -RxNetworkKit is a lightweight FRP networking framework. +RxNetworkKit is a generic reactive networking framework that leverages the stability and reliability of both Apple's [URLSession](https://developer.apple.com/documentation/foundation/urlsession) and [RxSwift](https://github.com/ReactiveX/RxSwift). -Built on top of Apple's [URLSession](https://developer.apple.com/documentation/foundation/urlsession) and uses the well-known [RxSwift](https://github.com/ReactiveX/RxSwift) FRP library. - -## Why RxNetworkKit? - -RxNetworkKit fits nicely on your project if you use RxSwift and RxCocoa mainly in your project. - -It makes use of RxSwift's traits at request level to acheive a high level of specialization for observed request sequence and expected output from it. - -### Full of Goodies: - -- includes download and upload capabillity with progress tracking all within the same observable sequence. cool, right? -- includes a request interceptor protocol that can be implemented for request adaptation and retry on failure. -- comes with a reachability class that you can observe from anywhere for reachability status. - -## Practical Examples - -### Simple API Call: - -``` -// Create `Session` instance. -let session = Session(configuration: .default) -// Create 'RESTClient' instance. -let restClient = RESTClient(session: session, requestInterceptor: self) -// Create `HTTPRequestRouter` instance. -let router = Router.default -// Make request observable sequence using request router. -let single: Single = restClient.request(router) -// Subscrible to sequence and observe events. -single - .observe(on: MainScheduler.instance) - .subscribe(onSuccess: { - print("Task Response: \($0)") - print("Task Completed!") - }, onFailure: { - print("Task Failure: \($0.localizedDescription)") - }, onDisposed: { - print("Subscription is disposed!") - }) - // Dispose subscription by dispose bag. - .disposed(by: disposeBag) -``` - -### Download Request: - -``` -// Create `Session` instance. -let session = Session(configuration: .default) -// Create 'HTTPClient' instance. -let httpClient = HTTPClient(session: session, requestInterceptor: self) -// Create `HTTPDownloadRequestRouter` instance. -let router = DownloadRouter.default -// Make download request observable sequence using request router. -let downloadObservable: Observable = httpClient.download(router) -// Subscrible to sequence and observe events. -downloadObservable - .observe(on: MainScheduler.instance) - .subscribe(onNext: { - switch $0 { - case .progress(let progress): - print("Download Task Progress: \(progress.fractionCompleted*100)%") - case .completedWithData(let data): - print("Download Task Completed with data: \(data).") - default: break - } - }, onError: { - print("Download Task Failure: \($0.localizedDescription)") - }, onCompleted: { - print("Download Task Completed!") - }) - // Dispose subscription by dispose bag. - .disposed(by: disposeBag) -``` - -### Upload Request: - -``` -// Create `Session` instance. -let session = Session(configuration: .default) -// Create 'HTTPClient' instance. -let httpClient = HTTPClient(session: session, requestInterceptor: self) -// Create `HTTPUploadRequestRouter` instance. -let router = UploadRouter.default -// Make 'HTTPUploadRequestFile' instance. -let fileData = Data() -guard let file = UploadFile(forKey: UUID().uuidString, withName: "testFile.txt", withData: fileData) else { return } -// Make upload request observable sequence using request router and upload file object. -let uploadObservable: Observable> = httpClient.upload(router, file) -// Subscrible to sequence and observe events. -uploadObservable - .observe(on: MainScheduler.instance) - .subscribe(onNext: { - switch $0 { - case .progress(let progress): - print("Upload Task Progress: \(progress.fractionCompleted*100)%") - case .completed(let model): - print("Upload Task Completed with Response: \(model)") - } - }, onError: { - print("Upload Task Failure: \($0.localizedDescription)") - }, onCompleted: { - print("Upload Task Completed!") - }) - // Dispose subscription by dispose bag. - .disposed(by: disposeBag) -``` +To get started with the framework, please refer to the [developer documentation](https://loay-ashraf.github.io/RxNetworkKit/). ## Requirements