I have a question about doing POST, PATCH, and PUT requests when using Alamofire and AlamofireObjectMapper. For example, lets say that I am doing a POST request to to send a object to a server. Can I pass a mapping as parameters for the request. Does it work similar to how RestKit encodes parameters into the body of the request as JSON?
Related
I'm creating a REST API from scratch for a preexisting iOS app whose API source code is, for all intents and purposes, no longer available. This means I'm analyzing how each endpoint expects requests sent to it to be formatted. One of those endpoints is communicated with via Alamofire's Session.upload(multipartFormData:to:method:headers:).
The multipartFormData is a closure parameter that is passed a MultipartFormData object, permits the consumer to mutate it (add key-value pairs to it in this case), and then return it from the closure.
My question is how does that addition of these key-value pairs to the MultipartFormData affect the format of the HTTP request. Up until this point every .post method has been passed a Dictionary<String, Any> and JSON has been specified as the encoding, so it has been straightforward to assess how the payload is uploaded (a single JSON object with a parameter for each entry in the dictionary). But it is not so straightforward with this Session.upload(multipartFormData:to:method:headers:) method. I essentially want to know how the key-value pairs are encoded into the request so I know how to decode them server side.
I am new in SOAP UI. I have an one scenario like I have to pass the access token value coming as a response to all the requests under the test suite.I ADD this token value in the next request header field called "TokenHeader" and it is working but my query is there any method that I can add which can be applied for all the soap requests, instead of changing the value every time for all request's header.How to automate this?Please guide me on this.
Just tab header of each request and add
TokenHeader = ${TestStepname#Response#jsonpath}
It will send token (received from response json) to http header of other request.
I'm trying to use RestKit because I'm expecting to make Core Data managed objects out of requests responses and it seemed like the framework was all about doing that and it seemed to be rather full featured.
But I'm having trouble getting my POST /user/login with parameters api_key=<value> (plus a separate JSON body) to end up a going out in a request like /user/login?api_key=<value>.
In the internals of RKObjectManager, requestWithMethod:path:parameters: does:
// NOTE: If the HTTP client has been subclasses, then the developer may be trying to perform signing on the request
NSDictionary *parametersForClient = [self.HTTPClient isMemberOfClass:[AFHTTPClient class]] ? nil : parameters;
request = [self.HTTPClient requestWithMethod:method path:path parameters:parametersForClient];
Do I have it right that this AFNetworking superclass method encodes parameters into the URL query? And does this mean the only way to ensure parameters are passed to that is to have my RKObjectManager use some subclass of AFHTTPClient?
And, according to the comment, supposedly this is only for sake of maybe a fringe case, something about request signing or something? Why is URL query-encoded request parameters not a common thing to do??
And getting things JSON encoded like I want does not seem to be as easy as I'd hoped either. Maybe it's a mistake for me to even try to use RestKit.
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.
I have seen how you can POST urlencoded forms and json using HttpClient.
But how do I POST arbitrary text?
My use case is that I already have my JSON string created, so I want to post the string directly, instead of constructing a dictionary.
Set the HTTPBody property on NSMutableURLRequest, and use anywhere in AFNetworking that takes an NSURLRequest parameter.