Skip to content

Commit 8d64fe5

Browse files
authored
Add Advanced Usage
1 parent 6d4603e commit 8d64fe5

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,82 @@ github "ProxymanApp/atlantis"
9292

9393
For Carthage with Xcode 12, please check out the workaround: https://github.com/Carthage/Carthage/blob/master/Documentation/Xcode12Workaround.md
9494

95+
## Advanded Usage
96+
By default, if your iOS app uses Apple's Networking classes (e.g URLSession or NSURLConnection) or using popular Networking libraries (e.g Alamofire and AFNetworking) to make an HTTP Request, Atlantis will work **OUT OF THE BOX**.
97+
98+
However, if your app doesn't use any one of them, Atlantis is not able to automatically capture the network traffic.
99+
100+
To resolve it, Atlantis offers certain functions to help you **manually*** add your Request and Response that will present on the Proxyman app as usual.
101+
102+
#### 1. My app uses C++ Network library and doesn't use URLSession, NSURLSession or any iOS Networking library
103+
You can construct the Request and Response for Atlantis from the following func
104+
```swift
105+
/// Handy func to manually add Atlantis' Request & Response, then sending to Proxyman for inspecting
106+
/// It's useful if your Request & Response are not URLRequest and URLResponse
107+
/// - Parameters:
108+
/// - request: Atlantis' request model
109+
/// - response: Atlantis' response model
110+
/// - responseBody: The body data of the response
111+
public class func add(request: Request,
112+
response: Response,
113+
responseBody: Data?) {
114+
```
115+
- Example:
116+
```swift
117+
@IBAction func getManualBtnOnClick(_ sender: Any) {
118+
// Init Request and Response
119+
let header = Header(key: "X-Data", value: "Atlantis")
120+
let jsonType = Header(key: "Content-Type", value: "application/json")
121+
let jsonObj: [String: Any] = ["country": "Singapore"]
122+
let data = try! JSONSerialization.data(withJSONObject: jsonObj, options: [])
123+
let request = Request(url: "https://proxyman.io/get/data", method: "GET", headers: [header, jsonType], body: data)
124+
let response = Response(statusCode: 200, headers: [Header(key: "X-Response", value: "Internal Error server"), jsonType])
125+
let responseObj: [String: Any] = ["error_response": "Not FOund"]
126+
let responseData = try! JSONSerialization.data(withJSONObject: responseObj, options: [])
127+
128+
// Add to Atlantis and show it on Proxyman app
129+
Atlantis.add(request: request, response: response, responseBody: responseData)
130+
}
131+
```
132+
133+
#### 2. My app use GRPC
134+
You can construct the Request and Response from GRPC models:
135+
```swift
136+
/// Helper func to convert GRPC message to Atlantis format that could show on Proxyman app as a HTTP Message
137+
/// - Parameters:
138+
/// - url: The url of the grpc message to distinguish each message
139+
/// - requestObject: Request object for the Request (Encodable)
140+
/// - responseObject: Response object for the Response (Encodable)
141+
/// - success: success state. Get from `CallResult.success`
142+
/// - statusCode: statusCode state. Get from `CallResult.statusCode`
143+
/// - statusMessage: statusMessage state. Get from `CallResult.statusMessage`
144+
public class func addGRPC<T, U>(url: String,
145+
requestObject: T?,
146+
responseObject: U?,
147+
success: Bool,
148+
statusCode: Int,
149+
statusMessage: String?) where T: Encodable, U: Encodable {}
150+
```
151+
- Example:
152+
```swift
153+
// Your GRPC services that is generated from SwiftGRPC
154+
private let client = NoteServiceServiceClient.init(address: "127.0.0.1:50051", secure: false)
155+
156+
// Note is a struct that is generated from a protobuf file
157+
func insertNote(note: Note, completion: @escaping(Note?, CallResult?) -> Void) {
158+
_ = try? client.insert(note, completion: { (createdNote, result) in
159+
160+
// Add to atlantis and show it on Proxyman app
161+
Atlantis.addGRPC(url: "https://my-server.com/grpc",
162+
requestObject: note,
163+
responseObject: createdNote,
164+
success: result.success,
165+
statusCode: result.statusCode.rawValue,
166+
statusMessage: result.statusMessage)
167+
})
168+
}
169+
```
170+
95171
## FAQ
96172
#### 1. How does Atlantis work?
97173

@@ -130,6 +206,7 @@ For some reason, Bonjour service might not be able to find Proxyman app.
130206
### 2. I could not use Debugging Tools on Atlantis's requests?
131207
Atlantis is built for inspecting the Network, not debugging purpose. If you would like to use Debugging Tools, please consider using normal HTTP Proxy
132208

209+
133210
## Credit
134211
- FLEX and maintainer team: https://github.com/FLEXTool/FLEX
135212
- @yagiz from Bagel project: https://github.com/yagiz/Bagel

0 commit comments

Comments
 (0)