How to send JSON dict in POST request? - objective-c

I have this JSON dictionary:
{"userId":"363008505", "userName":"almogsh11", "friends":[{"u":"2079823612","n":"she43"},{"u":"2010211025","n":"temy63c"}]}
It contains the "friends" array. I want to send this dictionary in post http request to server.
How can I do this?

You could use the AFNetworking framework. There are a couple of methods you could use, such as JSON Parameter Encoding and URL Form Parameter Encoding.

Related

FromQuery with FromBody fallback

I have a method which accept POST and GET verbs, How can I get a property bind from the querystring if it's a GET request and from body if it's a Post Request?
Extra point if it can databind from JSON and from form encoded bodies.

Post base64 to Amazon API Gateway

I've been searching a lot on this topic but no luck.
My API accepts a base64 string as a payload of a POST request. The base64 is the representation of an image. I use Amazon API gateway as a proxy. I've created a POST /uploadImage64 method in the resources tree, choosing HTTP as integration type.
In the "Method Request" block, API gateway allows me specifying only a JSON model in the "Request Body" section, but my payload is not application/json . Hence, the exported SDK does not allow posting any base64 payload.
Any suggestion is appreciated.
Thanks!
Roberto
Yeah the Models only support JSON so the generated SDK would have to either be something like { 'payload' -> base64 } or as Roberto suggested, extending the SDK yourself.
There really isn't a 'model' for base64 data that can be represented as a native object anyway, so I think generically extending or looking deeper in the SDK for the spot where you can just pass a string payload is what you want.

Call a POST rest api with AddJsonBody method vs. AddObject method

I am using RestSharp to do a REST API client application. If the format of request body (pay load) for a POST Rest Api call is JSON, I would like to know when I should use RestRequest.AddJsonBody() method and when RestRequest.AddObject() method. Thank you.
To send a JSON payload, use AddJsonBody. AddObject will extract name-value pairs from the object and add them as parameters.

Changing response serializer for a particular call inside AFHTTPSessionManager

I am subclassing AFHTTPSessionManager to make different POST requests to one server. All responses from the server are returned in JSON format, so I set response serializer for AFHTTPSessionManager to AFJSONResponseSerializer. But for one POST request I need to change response serializer to some other (leaving all other to use AFJSONResponseSerializer). Is is possible to do that?
Try AFCompoundResponseSerializer, you may add different serializers in it.

How to pass object to RESTful Service with GET request?

I have seen some posts in stackoverflow saying "sending list of items in the GET Method, is NOT allowed. It has to be accomplished via POST method only"
My code looks like
[OperationContract]
[WebGet(UriTemplate = "Employee/{emp}",RequestFormat=WebMessageFormat.Json)]
Employee GetEmpDetails(string emp);
and my input json object will be "{'id':1,'name':'test',....}
Is there any alternative way of achieving this issue.
Thanks
It is possible to send list of items with GET, it's just that out of the box only primitive values are supported. String values work just fine, but if you want to pass a complex object, you need to create a custom QueryStringConverter. The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/08/09/wcf-extensibility-querystringconverter.aspx explains how this can be done.
If you make your service RESTful you will most probably use HTTP PUT for Add method and HTTP POST for Update method. It is absolutely ok to pass object to these methods because objet will be part of HTTP request's body, not part of URI. URI is important for HTTP GET requests. HTTP GET requests should be only for data retrieval not for data modification.
You are mixing up HTTP GET/POST/... requests and REST GET/POST/PUT/DELETE/...
When you wanna request something RESTfully - you do a GET request. In your case I think it should look like
employee/{id}
or
employee/{name}
Please also note that usage of lowercase in the URI is preferable.
If you need multiple GET criteria, I think it could look like:
employee/id/{id}/name/{name}