DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Low-Code Development: Leverage low and no code to streamline your workflow so that you can focus on higher priorities.

DZone Security Research: Tell us your top security strategies in 2024, influence our research, and enter for a chance to win $!

Launch your software development career: Dive head first into the SDLC and learn how to build high-quality software and teams.

Open Source Migration Practices and Patterns: Explore key traits of migrating open-source software and its impact on software development.

Related

  • Operational Excellence Best Practices
  • Using CNTI/CNF Test Catalog for Non-Telco Cloud-Native Microservices
  • Resource Management in Kubernetes
  • Protecting Go Applications: Limiting the Number of Requests and Memory Consumption

Trending

  • When Not To Use Apache Kafka (Lightboard Video)
  • Strategies for Building Self-Healing Software Systems
  • Automate Message Queue Deployment on JBoss EAP
  • Mastering Unstructured Data Chaos With Datadobi StorageMAP 7.0
  1. DZone
  2. Coding
  3. Frameworks
  4. Five Minute Swift: Debugging Alamofire Requests

Five Minute Swift: Debugging Alamofire Requests

Learn how to use the power of extensions to see what how your HTTP requests are formed with Alamofire.

By 
James Sugrue user avatar
James Sugrue
DZone Core CORE ·
Feb. 14, 17 · Code Snippet
Like (4)
Save
Tweet
Share
16.1K Views

Join the DZone community and get the full member experience.

Join For Free

When REST API calls go wrong, it can be really frustrating to work out where the problem is. Are you missing a header? Or have you sent something incorrect in your request?

There's no shortage of debugging methods for this. There are traditional approaches like using Wireshark to debug all requests and responses, or by installing Charles as an HTTP Monitor on your machine. More recently, there have been some in-app debugging solutions like ResponseDetective which intercepts all calls made by the URLSession. Dotzu gives you a view into networking info, among other logs, so that you can view all calls made by your app.

However, there are times that you just need a really simple solution, without adding yet another framework to your app. If you're already using Alamofire, by leveraging the power of extensions, you'll be able to easy view outgoing requests. 

First, you'll need to define an extension to the Request class as follows:

extension Request {
    public func debugLog() -> Self {
        #if DEBUG
            debugPrint("=======================================")
            debugPrint(self)
            debugPrint("=======================================")
        #endif
        return self
    }
}


This extension will only run as you are debugging the application and prints out the entire Request to the console. 

To use the extension, just use debugLog() after defining your request, like so: 

  Alamofire.request(url).debugLog()
            .responseJSON( completionHandler: { response in
   })


Requests Swift (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Operational Excellence Best Practices
  • Using CNTI/CNF Test Catalog for Non-Telco Cloud-Native Microservices
  • Resource Management in Kubernetes
  • Protecting Go Applications: Limiting the Number of Requests and Memory Consumption

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: