The Restler framework has been built to use features of the newest versions of Swift. Inspiration for it is the Vapor library for building Server-side with Swift. What we love is functional programming, so you can build your desired request just calling some chained functions. The main goal of the framework is to provide a nice interface for making API requests the easiest as possible and the fastest as possible.
We think that README isn’t a good place for complete documentation so that’s why we decided to generate it to a folder inside the framework repository. Full documentation you can find in the Documentation folder. If you’re looking for a description of a specific protocol or class, we put here a list of the most important symbols.
Restler
RestlerType - it’s the main protocol which should be used when it comes to mocking or using Restler’s class’ instance.
RestlerErrorDecodable - a protocol to implement if an object should be decoded by the ErrorParser.
Instalation
Nothing is easier there - you just add the framework to the Swift Package Manager dependencies if you use one.
Otherwise you can use CocoaPods. If you use one simply add to your Podfile:
...
pod 'Restler/Core'
...
It’s important to specify it with /Core! (Changed in v1.0)
and call in your console:
pod install
Import the framework to the project:
import RestlerCore
and call it!
Usage Examples
Error parser
If you don’t want to add the same error to be parsed on a failure of every request, simply add the error directly to the error parser of the Restler object.
Encodes the object and puts it in query for the GET request.
Builds a request and returns publisher for Combine support.
Specifies the scheduler on which to receive elements from the publisher. In this case the main queue.
Get Data object from DataTaskPublisher.
Decode Profile object.
Handle the error
Assigns each element from a Publisher to a property on an object.
Stores this type-erasing cancellable instance in the specified collection.
Restler + RxSwift
First of all, you need to add RxRestler to your target you can do it simply in SPM. In CocoaPods you should add to your Podfile:
pod `Restler/Rx`
Then import RxRestler to every file it’s needed.
Restler(baseURL: myBaseURL)
.get(Endpoint.myProfile)
.query(anEncodableQueryObject)
.receive(on: .main) // 1
.decode(Profile.self) // 2
.rx // 3
.subscribe( // 4
onSuccess: { print("This is my profile:", $0) },
onError: { print("This is an error:", $0) })
.disposed(by: bag) // 5
Subscribe handlers will be called on the provided queue even if it’s done with RxSwift (setting a scheduler with this property set may cause some little delay between receiving a response and handling it but the handlers will be called on the provided scheduler).
Decode some type on successful response - Void, Data, or some custom object.
Move request to Rx usage. This returns Single<Profile> in this case.
Here we call already the RxSwift function.
Remember about adding the Disposable to the DisposeBag. The networking task will be canceled automatically if the bag will deinitialize.
Contribution
If you want to contribute in this framework, simply put your pull request here.
If you have found any bug, file it in the issues.
If you would like Restler to do something else, create an issue with a feature request.
Configuration
Clone the project and open the project’s folder in the terminal.
Run a configuration script: ./Scripts/configure.sh
Fill configuration file in folder Restler-Example/Restler-Example/Configuration named Debug.xcconfig with needed information.
Open the project in the folder Restler-Example. You can do it from the terminal: open Restler-Example/Restler-Example.xcodeproj
Run tests to be sure everything works properly.
Lint
Run command ./Scripts/pod_lib_lint.rb Restler.podspec to lint the podspec before pushing changes to the repo.
Restler
The Restler framework has been built to use features of the newest versions of Swift. Inspiration for it is the Vapor library for building Server-side with Swift. What we love is functional programming, so you can build your desired request just calling some chained functions. The main goal of the framework is to provide a nice interface for making API requests the easiest as possible and the fastest as possible.
List of Content
Documentation
We think that README isn’t a good place for complete documentation so that’s why we decided to generate it to a folder inside the framework repository. Full documentation you can find in the Documentation folder. If you’re looking for a description of a specific protocol or class, we put here a list of the most important symbols.
Restler
RestlerType - it’s the main protocol which should be used when it comes to mocking or using Restler’s class’ instance.
Request builder
All these protocols are defined in one file: RestlerRequestBuilderType
Request
Restler.Request - generic class for all request types provided by Restler.
Errors
unknownError
.Error parser
Instalation
Nothing is easier there - you just add the framework to the Swift Package Manager dependencies if you use one.
Otherwise you can use CocoaPods. If you use one simply add to your
Podfile
:It’s important to specify it with
/Core
! (Changed in v1.0) and call in your console:Import the framework to the project:
and call it!
Usage Examples
Error parser
If you don’t want to add the same error to be parsed on a failure of every request, simply add the error directly to the error parser of the Restler object.
If you don’t want to decode it anymore, simply stop decoding it:
Header
Setting header values is very easy. Simply set it as a dictionary:
If you’re using basic authentication in the “Authorization” key, simply provide username and password to the header:
Restler calls
GET
POST
Other
Any other method call is very similar to these two, but if you have questions simply create an issue.
Restler + Combine
Profile
object.DataTaskPublisher
.Profile
object.Restler + RxSwift
First of all, you need to add
RxRestler
to your target you can do it simply in SPM. In CocoaPods you should add to your Podfile:Then
import RxRestler
to every file it’s needed.Single<Profile>
in this case.Disposable
to theDisposeBag
. The networking task will be canceled automatically if thebag
will deinitialize.Contribution
If you want to contribute in this framework, simply put your pull request here.
If you have found any bug, file it in the issues.
If you would like Restler to do something else, create an issue with a feature request.
Configuration
./Scripts/configure.sh
Restler-Example/Restler-Example/Configuration
namedDebug.xcconfig
with needed information.Restler-Example
. You can do it from the terminal:open Restler-Example/Restler-Example.xcodeproj
Lint
Run command
./Scripts/pod_lib_lint.rb Restler.podspec
to lint the podspec before pushing changes to the repo.Releasing
cd Scripts/releaseTool
swift run ReleaseTool release ../..
Dependencies
Gems