Questions tagged [moya]

Open source network abstraction layer that encapsulates calling Alamofire directly.

Features of Moya include:

  • Compile-time checking for correct API endpoint accesses.
  • Lets you define a clear usage of different endpoints with associated enum values.
  • Treats test stubs as first-class citizens so unit testing is super-easy.
192 questions
19
votes
4 answers

How can I set timeout for requests using Moya pod?

I'm using Swift 3 and the Moya pod. I configured everything I needed using the Basic Usage, but I didn't find any function or variable that I can set the timeout (for every requests or for a specific request). How can I do this?
Roberto Sampaio
  • 481
  • 4
  • 14
18
votes
3 answers

Using retryWhen to update tokens based on http error code

I found this example on How to refresh oauth token using moya and rxswift which I had to alter slightly to get to compile. This code works 80% for my scenario. The problem with it is that it will run for all http errors, and not just 401 errors.…
tskulbru
  • 2,306
  • 1
  • 21
  • 38
12
votes
2 answers

How to upload image using multipart request with Moya Swift?

I'm using Moya 10.0.1 and I'm having a problem when I'm trying to upload an image to the server. I did follow the Multipart Upload example and this is my setup code: typealias UpdateUserAvatarParameters = (userId: Int, image: UIImage) enum…
Anh Pham
  • 2,004
  • 8
  • 16
  • 28
11
votes
3 answers

Enum element cannot be referenced as an instance member

I'm creating an API layer using Moya and keep getting the above mentioned error for the .updateMyWeightGoal target when I'm creating a request for an endpoint. goalAPI.request(target: .updateMyWeightGoal(weightGoalData: goalInfo), success: {…
Suman Roy
  • 653
  • 5
  • 17
9
votes
2 answers

Handling Network error in combination with binding to tableView (Moya, RxSwift, RxCocoa)

I am currently using Moya to make my network requests. I have implemented the following from one of the example projects @ https://github.com/DroidsOnRoids/RxSwiftExamples#tutorials Below I have set up restaurantSearch so that when someone enters…
pls
  • 1,302
  • 1
  • 20
  • 40
8
votes
2 answers

Moya stub request in BDD tests

I want to make a Moya stub request in my Quick/Nimble BDD tests. Moya has a sampleData parameter I created using a JSON file: var sampleData: Data { switch self { case .getPlaces: // Provided that project have a file named…
Svyatoslav
  • 1,301
  • 12
  • 19
8
votes
1 answer

Static framework linked to Cocoapod not found in Main project

I'm trying to add a static framework (Moya) to my private Cocoapod project through Carthage. My goal is to include Moya as a static framework in my private Cocoapod (SwiftModel) and use Moya as well in my main project (as SwiftModel has a dependency…
gpichler
  • 1,997
  • 2
  • 23
  • 44
7
votes
1 answer

Refreshing auth token with Moya

I'm using Moya to communicate with my API. For many of my endpoints, I require that the user be authenticated (i.e. a bearer token is based in the Authorization header). In the Moya documentation, here, I found how to include the Authorization…
user6724161
  • 175
  • 1
  • 11
7
votes
1 answer

How to pass the JSON body with POST request in moya

I'm using the moya library to make a POST request. In TargetType, I couldn't able to see any property to pass the parameters[JSON body] along with POST request. Here, I attach the TargetType public protocol TargetType { /// The target's base…
sathish
  • 451
  • 1
  • 3
  • 14
7
votes
1 answer

How do I check for internet using Moya and RxSwift?

As far as I understand Alamofire is pulled in with built in Reachability, so my own handler would look something like: import Alamofire let reachabilityManager = NetworkReachabilityManager() reachabilityManager.listener = { status in switch status…
AMAN77
  • 5,580
  • 7
  • 42
  • 59
6
votes
2 answers

How to synchronously refresh an access token using Alamofire + RxSwift

I have this generic fetchData() function in my NetworkManager class that is able to request make a authorised request to the network and if it fail (after a number of retries) emits an error that will restart my app (requesting a new login). I need…
chr0x
  • 855
  • 2
  • 11
  • 23
6
votes
6 answers

How do we debug/see the request being set over API with Moya?

How do we debug the request being set over to backend servers? I'd like to be able to see exactly or print out the full request with headers parameters, etc... that is being sent over to servers whenever I make any request by Moya
Hamid Shahsavari
  • 1,151
  • 18
  • 30
6
votes
2 answers

How to cancel multiple networking requests using Moya

I am currently using Moya to structure my networking calls. Per their docs, I have configured it as the following: enum SomeAPIService { case endPoint1(with: Object) case endPoint2(duration: Int) } When calling an endpoint (in this case,…
daspianist
  • 4,972
  • 8
  • 46
  • 87
6
votes
2 answers

How do I detect change in internet connection on iOS, delegate style?

I need a function to run only when the system detects there is no internet connection, then another function to run when the system detects an internet connection. I'm thinking of something like this: func onInternetConnection() { //Enable…
Berry
  • 1,595
  • 1
  • 18
  • 40
6
votes
1 answer

Custom Error Response Handling with Moya + RxSwift

I'm using Moya with RxSwift for networking in an iOS app, and I'd like to be able to consume my API's custom error responses when my Observers get calls to onError. The API always returns error responses in the following JSON format: { "error":…
Scott Storch
  • 688
  • 3
  • 8
  • 15
1
2 3
12 13