I have two Restful
web services:
service1: api.wego.com/flights/api/k/2/searches
and
service2: api.wego.com/flights/api/k/2/fares
service1's question:
I want to use AFJSONRequestOperation
to do a POST
request to serivce1 , the using of AFJSONRequestOperation
instead of RestKit
with this service is because I don't need to create any mapping for the returned response, I simply just want to save some of the returned data into local variables, but the problem is that service1 expects something like this JSON
in the post body:
{
"trips": [
{
"departure_code": "SIN",
"arrival_code": "HKG",
"outbound_date": "2013-11-29",
"inbound_date": "2013-12-06"
}
],
"adults_count": 1
}
the question: how to create an AFJSONRequestOperation
to post a request to service1 and send the above JSON
with the post body ?
service2's question:
I want to use RestKit 0.2x
to do a POST
request to this service, I know how to build up the mapping model, but according to the service docs, I have to send a JSON
object along with the post body that looks like this:
{
"id": "1376967853520",
"search_id": "IAXutjj0TAu0Wq-kvOMK6A",
"trip_id": "NYC:LON:2013-11-29:2013-12-06",
"fares_query_type": "route"
}
I used RestKit
previously to do Get
requests using getObjectsAtPath
method, but in this case I think I have to use postObject
method to do the POST
request but I'm not sure of that.
the question: how to do a POST
request to service2 using RestKit 0.2x
and send the above JSON
with the post body (considering that the mapping model is already set and ready to be used) ?
thank you so much for your kind help.
Create a dictionary and use NSJSONSerialisation
(This would produce data for you to set as the operation payload). Or, use RKObjectManager requestWithObject:method:path:parameters:
(which would create the URL request to send, with the payload data already set). Then create the request operation with that.
Yes, use the RKObjectManager postObject:...
method. You need to create request mapping and descriptor for the class of object you're going to post. Then just post with the object and path.