📈 GH Trending Explorer 🎲 Surprise me

← all repos

AliSoftware / OHHTTPStubs

git clone https://github.com/AliSoftware/OHHTTPStubs.git 9.1.0 · 5y ago 🔥 on GitHub Trending today

Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!

+0
stars, 24h · #570
—
stars, 7 days
—
stars, 30 days
5.1k
★ total
598
forks · 47 open issues

Star history starts 2026-10-20; the chart appears after the second daily snapshot.

LanguageObjective-C
LicenseMIT
Created2012-07-10 (14y ago)
Last push2y ago
Watchers107
OwnerUser

Seen on GitHub Trending

  • 2026-10-20 — #14 daily in objective-c

GitHub topics

Links

README excerpt
OHHTTPStubs
===========
`OHHTTPStubs` is a library designed to stub your network requests very easily. It can help you:
* test your apps with **fake network data** (stubbed from file) and **simulate slow networks**, to check your application behavior in bad network conditions
* write **unit tests** that use fake network data from your fixtures.
It works with `NSURLConnection`, `NSURLSession`, `AFNetworking`, `Alamofire` or any networking framework that use Cocoa's URL Loading System.
----
# Documentation & Usage Examples
`OHHTTPStubs` headers are fully documented using Appledoc-like / Headerdoc-like comments in the header files. You can also read the **online documentation** here.
## Basic example
 In Objective-C 
 [code] 
 In Swift 
This example is using the Swift helpers found in `OHHTTPStubsSwift.swift` provided by the `OHHTTPStubs/Swift` subspec or `OHHTTPStubs` package.
 [code] 
**Note**: if you're using `OHHTTPStubs`'s Swiftier API (`OHHTTPStubsSwift.swift` and the `Swift` subspec or `OHTTPStubsSwift` package), you can also compose the matcher functions like this: `stub(isScheme("http") && isHost("myhost")) { … }`
## More examples & Help Topics
* For a lot more examples, see the dedicated "Usage Examples" wiki page.
* The wiki also contain some articles that can help you get started with (and troubleshoot if needed) `OHHTTPStubs`.
## Recording requests to replay them later
Instead of writing the content of the stubs you want to use manually, you can use tools like SWHttpTrafficRecorder to record network requests into files. This way you can later use those files as stub responses. 
This tool can record all three formats that are supported by `OHHTTPStubs` (the `HTTPMessage` format, the simple response boby/content file, and the `Mocktail` format).
_(There are also other ways to perform a similar task, including using `curl -is >foo.response` to generate files compatible with the `HTTPMessage` format, or using other network recording libraries similar to `SWHttpTrafficRecorder`)._
# Compatibility
* `OHHTTPStubs` is compatible with **iOS5+**, **OS X 10.7+**, **tvOS**.
* `OHHTTPStubs` also works with `NSURLSession` as well as any network library wrapping them.
* `OHHTTPStubs` is **fully compatible with Swift 3.x, 4.x and Swift 5.x**.
_Nullability annotations have also been added to the ObjC API to allow a cleaner API when used from Swift even if you don't use the dedicated Swift API wrapper provided by `OHHTTPStubsSwift.swift`._
 Updating to Version 9.0+ 
* All classes dropped the `OH` prefix (`OHHHTTPStubs` -> `HTTPStubs`, `OHHTTPStubsResponse` -> `HTTPStubsResponse`, etc).
* The `OHPathHelpers` class was renamed `HTTPStubsPathHelpers`.
* No method and module names were changed.
# Installing in your projects
## CocoaPods
Using CocoaPods is the recommended way.
* If you **intend to use `OHHTTPStubs` from Objective-C only**, add `pod 'OHHTTPStubs'` to your `Podfile`.
* If you **intend to use `OHHTTPStubs` from Swift**, add `pod 'OHHTTPStubs/Swi