Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

303
Views
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

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

It is done by activating a plugin that Moya Already has it. it is NetworkLoggerPlugin. I need to change this line of code:

var provider = MoyaProvider<MainAPI>()

with:

var provider = MoyaProvider<MainAPI>(plugins: [NetworkLoggerPlugin(verbose: true)])

MOYA >= 14

let plugin: PluginType = NetworkLoggerPlugin(configuration: .init(logOptions: .verbose))

let provider = MoyaProvider<T>(plugins: [plugin])

Thanks to @Anbu.Karthik

over 4 years ago · Santiago Trujillo Report

0

Starting from Moya 14.0 you need to do this:

let loggerConfig = NetworkLoggerPlugin.Configuration(logOptions: .verbose)
let networkLogger = NetworkLoggerPlugin(configuration: loggerConfig)    
let provider = MoyaProvider<YourAPI>(plugins: [networkLogger])
over 4 years ago · Santiago Trujillo Report

0

If using Moya from 14, you can make your own verbose Plugin, like this:

struct VerbosePlugin: PluginType {
    let verbose: Bool

    func prepare(_ request: URLRequest, target: TargetType) -> URLRequest {
        #if DEBUG
        if let body = request.httpBody,
           let str = String(data: body, encoding: .utf8) {
            print("request to send: \(str))")
        }
        #endif
        return request
    }
}

and use: let provider = MoyaProvider<AuthService>(plugins: [VerbosePlugin(verbose: true)])

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!