-
Notifications
You must be signed in to change notification settings - Fork 14
/
objective-c.html
330 lines (238 loc) · 24.5 KB
/
objective-c.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<head>
<meta charset="utf-8">
<!-- Page title -->
<title>Unirest for Objective-C - Simplified, lightweight HTTP Request Library</title>
<!-- Gotsta have that favicon-->
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<!-- Viewport -->
<meta name="viewport" content="width=480">
<!-- Stylesheet -->
<link href="styles/library.css" rel="stylesheet" type="text/css" data-inprogress="" />
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet" />
</head>
<body>
<nav>
<div class="right">
<a href="https://www.mashape.com/jobs">Created by Mashape <span>(We're Hiring!)</span></a>
<a href="https://twitter.com/share" class="twitter-share-button" data-via="mashape" data-size="small" data-related="mashape" data-count="none">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<iframe src="http://ghbtns.com/github-btn.html?user=mashape&repo=unirest-obj-c&type=fork&size=small" allowtransparency="true" frameborder="0" scrolling="0" width="52" height="20"></iframe>
</div>
<a href="http://unirest.io"><span class="icon-chevron-left"></span> Go Back</a>
</nav>
<button onclick="topFunction()" id="myBtn" title="Go to top">Top</button>
<div style="padding:30px 30px 25px" class="documentation">
<div class="documentation"><h1>
<a id="user-content-unirest-for-objective-c" class="anchor" href="#unirest-for-objective-c" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Unirest for Objective-C</h1>
<p><a href="https://travis-ci.org/Mashape/unirest-obj-c"><img src="https://camo.githubusercontent.com/cddb905259d842f4d72391a6d15e8e722124ecb4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4d6173686170652f756e69726573742d6f626a2d632e7376673f7374796c653d666c6174" alt="Build Status" data-canonical-src="https://img.shields.io/travis/Mashape/unirest-obj-c.svg?style=flat" style="max-width:100%;"></a> <a href="http://cocoadocs.org/docsets/Unirest"><img src="https://camo.githubusercontent.com/77caf6debb1e0df4b7ff9ede236e4747e8d774c6/68747470733a2f2f696d672e736869656c64732e696f2f636f636f61706f64732f762f556e69726573742e7376673f7374796c653d666c6174" alt="version" data-canonical-src="https://img.shields.io/cocoapods/v/Unirest.svg?style=flat" style="max-width:100%;"></a> <a href="https://github.com/Mashape/unirest-obj-c/blob/master/LICENSE"><img src="https://camo.githubusercontent.com/ce52631c5c3977de350047dca60dea0c47146ebf/68747470733a2f2f696d672e736869656c64732e696f2f636f636f61706f64732f6c2f556e69726573742e7376673f7374796c653d666c6174" alt="License" data-canonical-src="https://img.shields.io/cocoapods/l/Unirest.svg?style=flat" style="max-width:100%;"></a> <a href="https://gitter.im/Mashape/unirest-obj-c"><img src="https://camo.githubusercontent.com/5818ff993808659f636e910854b9aefcda215da2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4769747465722d4a6f696e253230436861742d626c75652e7376673f7374796c653d666c6174" alt="Gitter" data-canonical-src="https://img.shields.io/badge/Gitter-Join%20Chat-blue.svg?style=flat" style="max-width:100%;"></a></p>
<p><a href="https://camo.githubusercontent.com/899e266a5194998ba3da232ee9bc97c48deab283/687474703a2f2f636c2e6c792f696d6167652f32503337335930393073324f2f496d616765253230323031352d31302d31322532306174253230392e34382e3036253230504d2e706e67" target="_blank"><img src="https://camo.githubusercontent.com/899e266a5194998ba3da232ee9bc97c48deab283/687474703a2f2f636c2e6c792f696d6167652f32503337335930393073324f2f496d616765253230323031352d31302d31322532306174253230392e34382e3036253230504d2e706e67" alt="" data-canonical-src="http://cl.ly/image/2P373Y090s2O/Image%202015-10-12%20at%209.48.06%20PM.png" style="max-width:100%;"></a></p>
<p><a href="http://unirest.io">Unirest</a> is a set of lightweight HTTP libraries available in multiple languages, built and maintained by <a href="https://github.com/Mashape">Mashape</a>, who also maintain the open-source API Gateway <a href="https://github.com/Mashape/kong">Kong</a>. </p>
<h2>
<a id="user-content-features" class="anchor" href="#features" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Features</h2>
<ul>
<li>Make <code>GET</code>, <code>POST</code>, <code>PUT</code>, <code>PATCH</code>, <code>DELETE</code> requests</li>
<li>Both syncronous and asynchronous (non-blocking) requests</li>
<li>It supports form parameters, file uploads and custom body entities</li>
<li>Supports gzip</li>
<li>Supports Basic Authentication natively</li>
<li>Customizable timeout</li>
<li>Customizable default headers for every request (DRY)</li>
<li>Automatic JSON parsing into native object (<code>NSDictionary</code> or <code>NSArray</code>) for JSON responses</li>
</ul>
<h2>
<a id="user-content-installing" class="anchor" href="#installing" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Installing</h2>
<p><a href="https://github.com/Mashape/unirest-obj-c/archive/master.zip">Download</a> the Objective-C Unirest Library from <a href="https://github.com/Mashape/unirest-obj-c">GitHub</a> (or clone the repo) and import the folder into your project. You can also install Unirest-obj-c with <a href="http://cocoapods.org/">CocoaPods</a>.</p>
<h3>
<a id="user-content-cocoapods" class="anchor" href="#cocoapods" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>CocoaPods</h3>
<p>If you decide to use CocoaPods, create a <code>Podfile</code> file in your project's folder:</p>
<div class="highlight highlight-source-shell"><pre>$ edit Podfile
platform :ios, <span class="pl-s"><span class="pl-pds">'</span>5.0<span class="pl-pds">'</span></span>
pod <span class="pl-s"><span class="pl-pds">'</span>Unirest<span class="pl-pds">'</span></span>, <span class="pl-s"><span class="pl-pds">'</span>~> 1.1.4<span class="pl-pds">'</span></span></pre></div>
<p>and then execute <code>pod install</code>. Make sure to always open the Xcode <strong>workspace</strong> instead of the project file when building your project:</p>
<div class="highlight highlight-source-shell"><pre>$ open App.xcworkspace</pre></div>
<p>Now you can import your dependencies:</p>
<div class="highlight highlight-source-objc"><pre>#<span class="pl-k">import</span> <span class="pl-s"><span class="pl-pds"><</span>UNIRest.h<span class="pl-pds">></span></span></pre></div>
<h3>
<a id="user-content-requirements" class="anchor" href="#requirements" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Requirements</h3>
<p>The Unirest-Obj-C client library requires ARC (Automatic Reference Counting) to be enabled in your Xcode project. To enable ARC select your project or target and then go to Build Settings and under the section Apple LLVM compiler 3.0 - Language you will see the option Objective-C Automatic Reference Counting:</p>
<p><a href="https://camo.githubusercontent.com/31234e7bfd3e5c4e65aa4a073ea157716cb4bfd3/687474703a2f2f756e69726573742e696f2f696d672f6172632d656e61626c652e706e67" target="_blank"><img src="https://camo.githubusercontent.com/31234e7bfd3e5c4e65aa4a073ea157716cb4bfd3/687474703a2f2f756e69726573742e696f2f696d672f6172632d656e61626c652e706e67" alt="Enable ARC in Xcode" data-canonical-src="http://unirest.io/img/arc-enable.png" style="max-width:100%;"></a></p>
<p>For existing projects, fortunately Xcode offers a tool to convert existing code to ARC, which is available at Edit -> Refactor -> Convert to Objective-C ARC</p>
<h2>
<a id="user-content-creating-request" class="anchor" href="#creating-request" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Creating Request</h2>
<p>So you're probably wondering how using Unirest makes creating requests in Objective-C easier, let's look at a working example:</p>
<div class="highlight highlight-source-objc"><pre><span class="pl-c1">NSDictionary</span>* headers = @{<span class="pl-s"><span class="pl-pds">@"</span>accept<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">@"</span>application/json<span class="pl-pds">"</span></span>};
<span class="pl-c1">NSDictionary</span>* parameters = @{<span class="pl-s"><span class="pl-pds">@"</span>parameter<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">@"</span>value<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">@"</span>foo<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">@"</span>bar<span class="pl-pds">"</span></span>};
UNIHTTPJsonResponse *response = [[UNIRest <span class="pl-c1">post:</span>^(UNISimpleRequest *request) {
[request <span class="pl-c1">setUrl:</span><span class="pl-s"><span class="pl-pds">@"</span>http://httpbin.org/post<span class="pl-pds">"</span></span>];
[request <span class="pl-c1">setHeaders:</span>headers];
[request <span class="pl-c1">setParameters:</span>parameters];
}] <span class="pl-c1">asJson</span>];</pre></div>
<p>Just like in the Unirest Java library the Objective-C library supports multiple response types given as the last parameter. In the example above we use <code>asJson</code> to get a JSON response, likewise there are <code>asBinary</code> and <code>asString</code> for responses of other nature such as file data and hypermedia responses.</p>
<h2>
<a id="user-content-asynchronous-requests" class="anchor" href="#asynchronous-requests" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Asynchronous Requests</h2>
<p>For non-blocking requests you will want to make an asychronous request to keep your application going while data is fetched or updated in the background, doing so with unirest is extremely easy with barely any code change from the previous example:</p>
<div class="highlight highlight-source-objc"><pre><span class="pl-c1">NSDictionary</span> *headers = @{<span class="pl-s"><span class="pl-pds">@"</span>accept<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">@"</span>application/json<span class="pl-pds">"</span></span>};
<span class="pl-c1">NSDictionary</span> *parameters = @{<span class="pl-s"><span class="pl-pds">@"</span>parameter<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">@"</span>value<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">@"</span>foo<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">@"</span>bar<span class="pl-pds">"</span></span>};
[[UNIRest <span class="pl-c1">post:</span>^(UNISimpleRequest *request) {
[request <span class="pl-c1">setUrl:</span><span class="pl-s"><span class="pl-pds">@"</span>http://httpbin.org/post<span class="pl-pds">"</span></span>];
[request <span class="pl-c1">setHeaders:</span>headers];
[request <span class="pl-c1">setParameters:</span>parameters];
}] <span class="pl-c1">asJsonAsync:</span>^(UNIHTTPJsonResponse* response, <span class="pl-c1">NSError</span> *error) {
<span class="pl-c">// This is the asyncronous callback block</span>
<span class="pl-k">NSInteger</span> code = response.<span class="pl-smi">code</span>;
<span class="pl-c1">NSDictionary</span> *responseHeaders = response.<span class="pl-smi">headers</span>;
UNIJsonNode *body = response.<span class="pl-smi">body</span>;
<span class="pl-c1">NSData</span> *rawBody = response.<span class="pl-smi">rawBody</span>;
}];</pre></div>
<h3>
<a id="user-content-cancel-asynchronous-request" class="anchor" href="#cancel-asynchronous-request" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Cancel Asynchronous Request</h3>
<p>You can cancel an asyncronous request by invoking the <code>cancel</code> method on the <code>UNIUrlConnection</code> object:</p>
<div class="highlight highlight-source-objc"><pre>UNIUrlConnection *asyncConnection = [[UNIRest <span class="pl-c1">get:</span>^(UNISimpleRequest *simpleRequest) {
[request <span class="pl-c1">setUrl:</span><span class="pl-s"><span class="pl-pds">@"</span>http://httpbin.org/get<span class="pl-pds">"</span></span>];
}] <span class="pl-c1">asJsonAsync:</span>^(UNIHTTPJsonResponse *response, <span class="pl-c1">NSError</span> *error) {
<span class="pl-c">// Do something</span>
}];
[asyncConnection <span class="pl-c1">cancel</span>]; <span class="pl-c">// Cancel request</span></pre></div>
<h2>
<a id="user-content-file-uploads" class="anchor" href="#file-uploads" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>File Uploads</h2>
<p>Transferring files through request with unirest in Objective-C can be done by creating a <code>NSURL</code> object and passing it along as a parameter value with a <code>UNISimpleRequest</code> like so:</p>
<div class="highlight highlight-source-objc"><pre><span class="pl-c1">NSDictionary</span>* headers = @{<span class="pl-s"><span class="pl-pds">@"</span>accept<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">@"</span>application/json<span class="pl-pds">"</span></span>};
<span class="pl-c1">NSURL</span>* file = <span class="pl-c1">nil</span>;
<span class="pl-c1">NSDictionary</span>* parameters = @{<span class="pl-s"><span class="pl-pds">@"</span>parameter<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">@"</span>value<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">@"</span>file<span class="pl-pds">"</span></span>: file};
UNIHTTPJsonResponse *response = [[UNIRest <span class="pl-c1">post:</span>^(UNISimpleRequest *request) {
[request <span class="pl-c1">setUrl:</span><span class="pl-s"><span class="pl-pds">@"</span>http://httpbin.org/post<span class="pl-pds">"</span></span>];
[request <span class="pl-c1">setHeaders:</span>headers];
[request <span class="pl-c1">setParameters:</span>parameters];
}] <span class="pl-c1">asJson</span>];</pre></div>
<h2>
<a id="user-content-custom-entity-body" class="anchor" href="#custom-entity-body" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Custom Entity Body</h2>
<p>To send a custom body such as JSON simply serialize your data utilizing the <code>NSJSONSerialization</code> with a <code>BodyRequest</code> and <code>[method]Entity</code> instead of just <code>[method]</code> block like so:</p>
<div class="highlight highlight-source-objc"><pre><span class="pl-c1">NSDictionary</span> *headers = @{<span class="pl-s"><span class="pl-pds">@"</span>accept<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">@"</span>application/json<span class="pl-pds">"</span></span>};
<span class="pl-c1">NSDictionary</span> *parameters = @{<span class="pl-s"><span class="pl-pds">@"</span>parameter<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">@"</span>value<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">@"</span>foo<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">@"</span>bar<span class="pl-pds">"</span></span>};
UNIHTTPJsonResponse *response = [[UNIRest <span class="pl-c1">postEntity:</span>^(UNIBodyRequest *request) {
[request <span class="pl-c1">setUrl:</span><span class="pl-s"><span class="pl-pds">@"</span>http://httpbin.org/post<span class="pl-pds">"</span></span>];
[request <span class="pl-c1">setHeaders:</span>headers];
<span class="pl-c">// Converting NSDictionary to JSON:</span>
[request <span class="pl-c1">setBody:</span>[<span class="pl-c1">NSJSONSerialization</span> <span class="pl-c1">dataWithJSONObject:</span>parameters <span class="pl-c1">options:</span><span class="pl-c1">0</span> <span class="pl-c1">error:</span><span class="pl-c1">nil</span>]];
}] <span class="pl-c1">asJson</span>];</pre></div>
<h2>
<a id="user-content-basic-authentication" class="anchor" href="#basic-authentication" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Basic Authentication</h2>
<p>Authenticating the request with basic authentication can be done by setting the <code>username</code> and <code>password</code> properties in the builder:</p>
<div class="highlight highlight-source-objc"><pre>UNIHTTPJsonResponse *response = [[UNIRest <span class="pl-c1">get:</span>^(UNISimpleRequest *request) {
[request <span class="pl-c1">setUrl:</span><span class="pl-s"><span class="pl-pds">@"</span>http://httpbin.org/get<span class="pl-pds">"</span></span>];
[request <span class="pl-c1">setUsername:</span><span class="pl-s"><span class="pl-pds">@"</span>user<span class="pl-pds">"</span></span>];
[request <span class="pl-c1">setPassword:</span><span class="pl-s"><span class="pl-pds">@"</span>password<span class="pl-pds">"</span></span>];
}] <span class="pl-c1">asJson</span>];</pre></div>
<h1>
<a id="user-content-request" class="anchor" href="#request" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Request</h1>
<p>The Objective-C unirest library uses configuration blocks of type UNISimpleRequest and UNIBodyRequest to configure the URL, Headers, and Parameters / Body of the request.</p>
<div class="highlight highlight-source-objc"><pre>+(UNIHTTPRequest*) get:(<span class="pl-k">void</span> (^)(UNISimpleRequestBlock*)) config;
+(UNIHTTPRequestWithBody*) post:(<span class="pl-k">void</span> (^)(UNISimpleRequestBlock*)) config;
+(UNIHTTPRequestWithBody*) postEntity:(<span class="pl-k">void</span> (^)(UNIBodyRequestBlock*)) config;
+(UNIHTTPRequestWithBody*) put:(<span class="pl-k">void</span> (^)(UNISimpleRequestBlock*)) config;
+(UNIHTTPRequestWithBody*) putEntity:(<span class="pl-k">void</span> (^)(UNIBodyRequestBlock*)) config;
+(UNIHTTPRequestWithBody*) patch:(<span class="pl-k">void</span> (^)(UNISimpleRequestBlock*)) config;
+(UNIHTTPRequestWithBody*) patchEntity:(<span class="pl-k">void</span> (^)(UNIBodyRequestBlock*)) config;
+(UNIHTTPRequestWithBody*) delete:(<span class="pl-k">void</span> (^)(UNISimpleRequestBlock*)) config;
+(UNIHTTPRequestWithBody*) deleteEntity:(<span class="pl-k">void</span> (^)(UNIBodyRequestBlock*)) config;</pre></div>
<ul>
<li>
<p><code>UNIHTTPRequest</code> <code>[UNIRest get:</code> <code>(void (^)(UNISimpleRequestBlock*))] config;</code> </p>
<p>Sends equivalent request with method type to given URL</p>
</li>
<li>
<p><code>UNIHTTPRequestWithBody</code> <code>[UNIRest (post|postEntity):</code> <code>(void (^)(UNISimpleRequestBlock|UNIBodyRequestBlock)(*))] config;</code> </p>
<p>Sends equivalent request with method type to given URL</p>
</li>
<li>
<p><code>UNIHTTPRequestWithBody</code> <code>[UNIRest (put|putEntity):</code> <code>(void (^)(UNISimpleRequestBlock|UNIBodyRequestBlock)(*))] config;</code> </p>
<p>Sends equivalent request with method type to given URL</p>
</li>
<li>
<p><code>UNIHTTPRequestWithBody</code> <code>[UNIRest (patch|patchEntity):</code> <code>(void (^)(UNISimpleRequestBlock|UNIBodyRequestBlock)(*))] config;</code> </p>
<p>Sends equivalent request with method type to given URL</p>
</li>
<li>
<p><code>UNIHTTPRequestWithBody</code> <code>[UNIRest (delete|deleteEntity):</code> <code>(void (^)(UNISimpleRequestBlock|UNIBodyRequestBlock)(*))] config;</code></p>
<p>Sends equivalent request with method type to given URL</p>
</li>
</ul>
<h1>
<a id="user-content-response" class="anchor" href="#response" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Response</h1>
<p>The <code>UNIHTTPRequest</code> and <code>UNIHTTPRequestWithBody</code> can then be executed by calling one of:</p>
<div class="highlight highlight-source-objc"><pre>-(UNIHTTPStringResponse*) asString;
-(UNIHTTPStringResponse*) asString:(<span class="pl-c1">NSError</span>**) error;
-(UNIUrlConnection*) asStringAsync:(UNIHTTPStringResponseBlock) response;
-(UNIHTTPBinaryResponse*) asBinary;
-(UNIHTTPBinaryResponse*) asBinary:(<span class="pl-c1">NSError</span>**) error;
-(UNIUrlConnection*) asBinaryAsync:(UNIHTTPBinaryResponseBlock) response;
-(UNIHTTPJsonResponse*) asJson;
-(UNIHTTPJsonResponse*) asJson:(<span class="pl-c1">NSError</span>**) error;
-(UNIUrlConnection*) asJsonAsync:(UNIHTTPJsonResponseBlock) response;</pre></div>
<ul>
<li>
<p><code>-(UNIHTTPStringResponse*)</code> <code>asString;</code> </p>
<p>Blocking request call with response returned as string for Hypermedia APIs or other.</p>
</li>
<li>
<p><code>-(UNIHTTPStringResponse*) asString:(NSError**) error;</code></p>
<p>Blocking request call with response returned as string and error handling. </p>
</li>
<li>
<p><code>-(UNIUrlConnection*) asStringAsync:(UNIHTTPStringResponseBlock) response;</code> </p>
<p>Asynchronous request call with response returned as string for Hypermedia APIs or other.</p>
</li>
<li>
<p><code>-(UNIHTTPBinaryResponse*)</code> <code>asBinary;</code> </p>
<p>Blocking request call with response returned as binary output for files and other media.</p>
</li>
<li>
<p><code>-(UNIHTTPBinaryResponse*) asBinary:(NSError**) error;</code></p>
<p>Blocking request call with response returned as binary output and error handling. </p>
</li>
<li>
<p><code>-(UNIUrlConnection*) asBinaryAsync:(UNIHTTPBinaryResponseBlock) response;</code> </p>
<p>Asynchronous request call with response returned as binary output for files and other media.</p>
</li>
<li>
<p><code>-(UNIHTTPJsonResponse*)</code> <code>asJson;</code> </p>
<p>Blocking request call with response returned as JSON. </p>
</li>
<li>
<p><code>-(UNIHTTPJsonResponse*) asString:(NSError**) error;</code></p>
<p>Blocking request call with response returned as JSON and error handling. </p>
</li>
<li>
<p><code>-(UNIUrlConnection*) asJsonAsync:(UNIHTTPJsonResponseBlock) response;</code> </p>
<p>Asynchronous request call with response returned as JSON.</p>
</li>
</ul>
<h1>
<a id="user-content-advanced-configuration" class="anchor" href="#advanced-configuration" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Advanced Configuration</h1>
<p>You can set some advanced configuration to tune Unirest-Obj-C:</p>
<h3>
<a id="user-content-timeout" class="anchor" href="#timeout" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Timeout</h3>
<p>You can set a custom timeout value (in <strong>seconds</strong>):</p>
<div class="highlight highlight-source-objc"><pre>[UNIRest <span class="pl-c1">timeout:</span><span class="pl-c1">2</span>];</pre></div>
<p>By default the timeout is <code>60</code>.</p>
<h3>
<a id="user-content-default-request-headers" class="anchor" href="#default-request-headers" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Default Request Headers</h3>
<p>You can set default headers that will be sent on every request:</p>
<div class="highlight highlight-source-objc"><pre>[UNIRest <span class="pl-c1">defaultHeader:</span><span class="pl-s"><span class="pl-pds">@"</span>Header1<span class="pl-pds">"</span></span> <span class="pl-c1">value:</span><span class="pl-s"><span class="pl-pds">@"</span>Value1<span class="pl-pds">"</span></span>];
[UNIRest <span class="pl-c1">defaultHeader:</span><span class="pl-s"><span class="pl-pds">@"</span>Header2<span class="pl-pds">"</span></span> <span class="pl-c1">value:</span><span class="pl-s"><span class="pl-pds">@"</span>Value2<span class="pl-pds">"</span></span>];</pre></div>
<p>You can clear the default headers anytime with:</p>
<div class="highlight highlight-source-objc"><pre>[UNIRest <span class="pl-c1">clearDefaultHeaders</span>];</pre></div>
<hr>
<p>Made with ♥ from the <a href="https://www.mashape.com/">Mashape</a> team</p>
</div>
<script type="text/javascript" src="//mashape.github.io/notification-bar/embed.js" async defer></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">
$('a img').parent().css('border-bottom', '0px')
</script>
<script type="text/javascript">
var analytics=analytics||[];analytics.load=function(e){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"===document.location.protocol?"https://":"http://")+"d2dq2ahtl5zl1z.cloudfront.NET/analytics.js/v1/"+e+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);var r=function(e){return function(){analytics.push([e].concat(Array.prototype.slice.call(arguments,0)))}},i=["identify","track","trackLink","trackForm","trackClick","trackSubmit","pageview","ab","alias","ready"];for(var s=0;s<i.length;s++)analytics[i[s]]=r(i[s])}; analytics.load("xsv6p66v1y");
</script>
<script src="script/script.js"></script>
</body>
</html>