In the Alamofire 5 Beta, SessionManager
has been replaced by Session
.
I am wondering what the procedure is now for assigning a RequestAdapter, as this was a var
in Alamofire 4, but in Alamofire 5 it's now a let
constant. Hence the following code:
var session = Session()
session.adapter = AccessTokenAdapter
throws a compile-time error, "Cannot assign to property: 'adapter' is a 'let' constant"
The end goal is to set custom header fields such as JWT token.
Session creates and manages Alamofire's Request types during their lifetimes. It also provides common functionality for all Request s, including queuing, interception, trust management, redirect handling, and response cache handling. default. Shared singleton instance used by all AF. request APIs.
Alamofire's RequestInterceptor protocol ( RequestAdapter & RequestRetrier ) provides important and powerful request adaptation and retry features. It can be applied at both the Session and Request level.
Advantages of Using AlamofireUsing Alamofire will give a cleaner project. API call interactions (POST/GET/PUT/etc.) will be easier and more understable. Alamofire simplifies a number of common networking tasks that makes development faster and easier.
You should conform to 'RequestInterceptor' protocol in your class, which have identical methods:
adapt and retry as in RequestAdapter and RequestRetrier.
Then you just pass it to request:
AF.request(urlRequest, interceptor: RequestInterceptor? = nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With