mxcl / PromiseKit

Promises for Swift & ObjC.
MIT License
14.24k stars 1.46k forks source link

Support for sending POST request with nested JSON-data #129

Closed jjabba closed 9 years ago

jjabba commented 9 years ago

I'm using the swift version of PromiseKit. I've been trying to use NSURLConnection.POST to send a request to an JSON::RPC2 compatible API. I need to send JSON in my request such as: { "jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1 }

But I havn't found a suitable construct for such a POST-request. All NSURLConnection.POST(...) variants seem to want flat json on the form: [String: String] (i.e Dictionary<String, String>)

mxcl commented 9 years ago

The underlying OMGHTTPURLRQ supports this. PromiseKit should have a method added, so maybe submit a PR?

NSURLRequest *`rq = [OMGHTTPURLRQ POST:url JSON:jsonDictionary];
PMKPromise *promise = [NSURLConnection promise:rq];
mxcl commented 9 years ago

The existing POST requests don't send JSON anyway, they send form url encoded data, with nesting support.