I have recently transferred my app over to stack mob, however I'm having difficulty with using the REST Api within my AFHTTP framework. Stackmob returns it's own version of the application/json response. It is actually returned as application/vnd.stackmob+json;
The AFHttp framework doesn't accept this, therefore I need a way of either asking stackmob to only return a standard application/json response, or tweak AFHTTP to accept this customer stackmob response.
Any help would be appreciated.
Related
it's my first post on StackOverflow :)
We're writing RESTful API backend using Spring Data Rest. To add association we're using the request:
POST /favouriteFolders/7/posts HTTP/1.1
Host: localhost:8080
Content-Type: text/uri-list
http://localhost:8080/posts/68
http://localhost:8080/posts/418
Request format is described here:
http://docs.spring.io/spring-data/rest/docs/2.5.1.RELEASE/reference/html/#_post_2
Our iOS developer has problem sending this kind of request using RestKit
https://github.com/RestKit/RestKit
Any ideas how to use RestKit in this situation?
Or maybe we should use other REST client to handle this specific requests ?
Thanks in advance!
I am currently building and API that will be consumed by an iOS client using RestKit. For the POST (create) operation, I am returning a standard 202 Accepted status with no content. The objectID is set in the location header as the creation on the API is async.
The issue is that the iOS dev has indicated that RestKit does not allow you to access the header information on the response object. Is it possible to access the response object without using the mapping feature in RestKit?
RestKit returns to you the operation which processed the request / response and from there you can navigate through to get the HTTP processing operation and the response object (which contains the headers).
I have an iOS app that is working and able to connect to a RESTful PHP Webservice. The webservice was initially built in native PHP and now I am migrating it to a Symfony2 web service. On the iOS side, I am sending requests as JSON, the server processes the data and returns a JSON response data, everything works pretty well.
Now, my symfony2 webservice is able to respond with the correct response to requests made from the browser window or terminal using httpie (for testing) and it returns json data in the browswer window if I specify .json in the parameters. However, I am not sure how to make the iOS app send the request rather than the browser. I am using the FOSRestBundle if that information is of any significance. Here is an example from the terminal:
http http://serveripaddress/web/app_dev.php/users/1.json Accept:application/json
It returns json data representation of the user with the id = 1 as expected:
HTTP/1.1 200 OK
Allow: GET, PUT, DELETE
Cache-Control: no-cache
Content-Type: application/json
Date: Fri, 29 Nov 2013 20:15:43 GMT
Server: Apache/2.2.22 (Ubuntu)
Set-Cookie: PHPSESSID=n8o72oq61isruuov1bqgc9udf5; path=/
Transfer-Encoding: chunked
X-Debug-Token: 6c3818
X-Powered-By: PHP/5.3.10-1ubuntu3.8
{
"id": 1,
"last_name": "Robinson",
"first_name": "Jack",
....More data truncated ...
}
From my browser, I can get the same result by using: http://serveripaddress/web/app_dev.php/users/1.json in the address bar. How can I make the iOS app send the same request? I guess the only change I need is in the symfony2 code to accept the request? Kindly give a brief example and I can figure out the rest from the example.
Edited with more detail:
Just to clarify, what I need is how to initiate a connection to the server-side REST Symfony2 application. Again, this I have previously done when using native PHP but how do I connect to a Symfony2 route? While using the native version, what I did was to construct a dictionaryWithObjectandKeys passing key value pairs of the command (on the PHP side) and the arguments as JSON and having the server side return JSON data response and a success or failure, simple and straightforward. How can this be done if I am using Symfony2 which I guess the commands now become a route? I am using AFNetworking and everything on the iOS client side should not need changes except the part where I connect to Symfony2. Kindly give an example to give me a concrete picture.
You can use AFNetworking 2 for example. It is a complete framework that allows you to consume web services (and more).
By the way, you could simply use (and fire) NSURLRequest, but if your application interact a lot with a webService i recommend to use AFNetworking. (Trust me, it is really something that you want to know how to use if you want to make apps on iOS)
I think binding to session and cookies may violate REST nature. I strongly recommend you to use something like WSSE. You can use EscapeWSSEAuthenticationBundle for WSSE. Or create your own.
Also useful link to dive deep:
How to create a custom Authentication Provider
Configure WSSE on Symfony2 with FOSRestBundle
I found the MVC API Action filter which should automatically check if the request demands a json response and if so automatically serialize in json the model i was sending to the view, right ?!
http://mvcapi.codeplex.com/
I found many examples but the thing is they all assume that the request will be sent by an Ajax call in which i can clearly specify it's a json request.
I want to call the action directly from my browser but i'm not without any specification it simply returns the view
How do i specify in the url that i'm requesting a json response?
I know of the library that you write of, but haven't used it. I shied away from using it when I saw that it never seems to have made it out of Beta on Codeplex and hasn't been updated in over a year.
That aside, in the methodology being used, the URL doesn't determine the data type coming back, the Http Accept Headers are what does it. This is a more RESTful approach to returning data.
You'll note on the link that you provided in the Request section that
Accept: application/json, text/javascript, */*
application/json is what tells the service to return json. You may find other examples on the web that say text/json instead, and they should work also, but application/json is the correct standard.
If you're using jQuery, you can use $.ajax and specify dataType: 'json' or just use the $.getJson method directly.
Can ASIHttpRequest call Restful web service ? I knew that Restkit is good at it.
If no,any easy way to convert ?
Can we say that ASIHttpRequest is good at calling soap based web service ?
Thanks for your comments !
ASIHTTPRequest simply does a HTTP request. Nothing more, nothing less. Since REST is also just an HTTP request, you can use ASIHTTPRequest just fine with a restful web service. It doesn't do any parsing of the response, though, so if the response is JSON you still have to parse that yourself.
You can also use ASIHTTPRequest for SOAP but you have to construct the XML by yourself (or using some other library) and parse the XML response by yourself as well. For SOAP you may want to use http://sudzc.com/ instead.