Guide · Open source
How to use Alamofire: requests, validation and auth in Swift
Updated · written with AI from the project's own documentation and checked against our catalogue data
Alamofire is an open-source HTTP networking library written in Swift that wraps Apple's URLSession. This guide explains what it does, how to install it, and how to make requests, validate responses and add authentication. It is aimed at developers building iOS or macOS apps that call web APIs.
Quick start
- 1Check your requirements. Confirm you have Xcode 16.0 or later and a project using Swift Package Manager, CocoaPods or Carthage.
- 2Add Alamofire to your project. Install the library with your chosen package manager, or clone the repository with git clone https://github.com/Alamofire/Alamofire.git.
- 3Import the module. Add import Alamofire at the top of the Swift file where you make network calls.
- 4Make a request with AF.request. Call AF.request with a URL string and chain the methods you need.
- 5Validate and parse the response. Chain validate() and a serializer such as serializingDecodable, then await the .response property.
- 6Debug when needed. Use debugPrint on the response or cURLDescription to inspect the request.
What Alamofire does and who it is for
Alamofire lets you send requests, encode parameters, upload and download files, validate responses and handle authentication in a few lines of code. It sits on top of Apple's URLSession rather than replacing it.
The README lists iOS 10.0+, macOS 10.12+, tvOS 10.0+ and watchOS 3.0+ as fully tested platforms. Linux, Windows and Android are described as building but unsupported.
- Best for Swift developers building iOS or macOS apps that call web APIs.
- Useful when you want built-in retry, authentication and response validation without writing that logic yourself.
- Not a fit for non-Swift projects, or for teams that want only URLSession with no extra layer.
Install Alamofire with Swift Package Manager, CocoaPods or Carthage
Alamofire supports Swift Package Manager, CocoaPods and Carthage, and can also be added manually. The README lists Xcode 16.0 or later (minimum Swift version 6.0) as the requirement for the current release line.
The README also gives a command to clone the repository directly. Use the package manager approach that matches your project setup.
- Swift Package Manager: add the Alamofire package to your Xcode project or Package.swift.
- CocoaPods and Carthage are also supported according to the README.
- Clone the repository with: git clone https://github.com/Alamofire/Alamofire.git
git clone https://github.com/Alamofire/Alamofire.gitMake your first request with AF.request
The main entry point is AF.request, which accepts a URL string and returns a request you can chain methods onto. The README's example shows that strings are converted to URLs automatically.
Chainable methods such as validate() and serializingDecodable(...) let you describe the whole pipeline in one expression. Use await with the .response property when you want Swift concurrency.
- Pass a URL string to AF.request.
- Chain .validate() to check the response code and Content-Type.
- Chain .serializingDecodable(YourType.self) to parse JSON into a Decodable type.
- Await .response to get the full response with metrics and a parsed body.
let response = await AF.request("https://httpbin.org/get", interceptor: .retryPolicy)
.authenticate(username: "user", password: "pass")
.validate()
.serializingDecodable(DecodableType.self)
.response
debugPrint(response)Add authentication, retry and caching
Alamofire supports authentication with URLCredential and automatic HTTP Basic Auth through the authenticate method. The README also lists retry through request interceptors and response caching as built-in features.
Retry is configured with an interceptor. The README mentions dynamically adapting and retrying requests through RequestInterceptor, which is covered in the Advanced Usage documentation.
- Basic Auth: .authenticate(username:password:) as shown in the README example.
- Retry: pass an interceptor such as .retryPolicy when creating the request.
- Caching: use .cacheResponse(using:) to customise caching behaviour.
- Redirects: use .redirect(using:) to control how redirects are followed.
Debug requests with cURL output and metrics
Alamofire can produce a cURL command for a request, which helps when you need to reproduce a call outside your app. The README shows this through the cURLDescription method.
The README also mentions statistical metrics and a detailed response description printed with debugPrint, which are useful when a request misbehaves.
- Use .cURLDescription to print an equivalent cURL command.
- Print the full response with debugPrint(response) for a detailed description.
- Use Alamofire's metrics output to see timing information for a request.
debugPrint(response)Secure connections and advanced features
For secure connections, Alamofire supports TLS certificate and public key pinning. Advanced topics such as custom session managers, routing, Combine support and network reachability are covered in the project's Advanced Usage documentation.
Upload and download progress closures, multipart uploads and resumable downloads are also listed as features.
- TLS certificate and public key pinning.
- Upload and download progress closures.
- Multipart upload and file download support.
- Network reachability checks.
What people use it for
- Calling a REST API from an iOS app and decoding JSON into Swift types.
- Uploading files or multipart form data from a macOS app.
- Downloading large files to disk with progress reporting.
- Adding Basic Auth and automatic retry to calls against a flaky web service.
- Pinning a server certificate or public key for a more secure connection.
Frequently asked questions
Is Alamofire free to use?
Yes. Alamofire is released under the MIT licence, as stated in the project's README. Check the LICENSE file in the repository for the full terms.
What are the requirements for Alamofire?
The README lists Xcode 16.0 or later, with a minimum Swift version of 6.0. Fully tested platforms are iOS 10.0+, macOS 10.12+, tvOS 10.0+ and watchOS 3.0+.
How do I install Alamofire?
You can install it with Swift Package Manager, CocoaPods or Carthage, or add it manually. The README also gives a command to clone the repository with git.
Does Alamofire work on Linux or Windows?
The README lists Linux, Windows and Android as building but unsupported. It is designed mainly for Apple platforms.
Is Alamofire better than URLSession?
Alamofire adds a higher-level API on top of URLSession, including parameter encoding, validation, retry and auth. If you only need simple requests, URLSession alone avoids an extra dependency.
What are the alternatives to Alamofire?
Projects mentioned for comparison include URLSession, Moya, Apollo iOS and Get. URLSession needs no extra dependency, while Moya and Apollo iOS suit different architectures or GraphQL use.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Alamofire suits Swift developers building iOS or macOS apps who want retry, authentication, validation and concurrency support without writing that logic from scratch. If you need only basic requests, want zero dependencies, or work outside Swift and Apple platforms, use URLSession directly or another option.
Install options & downloads