I´m trying to access a web service from my iOS application. In the documentation it says that I should use a query string to pass the parameters but I´m not sure on how to use this.
I using the AFNetworking framework. Made a POST request earlier and it worked just fine, but not sure on how to write and pass a query string.
The 'query string' is produced by AFNetworking. Just use the getPath:parameter:... method and provide the parameter dictionary. Make sure the dictionary has a key for each of the query names required by the web service.
For example:
[client getPath: #"transactions"
parameters: #{ #"api_key" : ksomeAPIKey,
#"user_id" : user_id }
...]
will be converted, by AFNetworking, to:
GET <baseURL>/transactions?api_key=...&user_id=...
Related
So I am aware of the fact that you can get the files in a repository by using
https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}
API.
The API also supports the q parameter where you can query the resulting json object based on various fields in it.
I wanted to know if one can use this query parameter to fetch the files based on certain extensions?
Like the JSON object also contains a field "mimetype" which defines the mime type of the files.
I did use the following API call
https://api.bitbucket.org/2.0/repositories/{workspace}/openapi/src/master/?max_depth=100&q=path+%7E+%22.js%22&pagelen=100
To fetch all the files which contain the string ".js" in the path parameter.
But while querying the mimetype parameter I was not able to do the same using
https://api.bitbucket.org/2.0/repositories/{workspace}/openapi/src/master/?max_depth=100&q=mimetype+%3D+%22application%2Fjavascript%22&pagelen=100
This call returned error.
Can anybody let me know how can you query based on mimetype or if possible fetch the files based on extension
Note: I know about the Code search API but that is not an option as it has large limitations.
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.
Trying to use deployd.com framework for simulating a backend service. I am fairly new to deployd, appreciate any example or pointer in the right direction. Trying to retrieve an object using POST method. It looks like POST is used to create objects.
In my case, POST data contains a few query fields that will be used to query an object and send json back. Is this possible using deployd by modifying onPost method or some other way?
I cannot use GET with query parms due to security restrictions.
here is post request data
[
{
customer:"sam",
city:"noWhere",
}
]
the POST event should query by customer and city, then return matching customer object
[
{
customer:"sam",
postcode:"352345",
city:"noWhere",
country:"US"
}
]
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.