Flex Is Not Friendly To REST


I am a big fan of Flex until now and the reason is the HTTPService that Flex provides doesn’t play well with REST. You see I am developing an application that uses Jersey/Spring/JPA on the server side and my plan was to use Flex to talk to the server side using Restful style web services. The problem is HTTPService class has several major limitations:

  1. Only GET and POST methods are supported out of the box (unless you use FDS and set useProxy attribute to true)
  2. Not able to set request headers and there is no access to response headers. Therefore I am not able to access the response body in the case of an error.
  3. It HTTPService gets a status code anything other 200, it consider an error. (event 201, ouch!!). The FaultEvent doesn’t provide information about the status code any response body. The Flex client will have no idea what went wrong.

I have spent quite a bit of time reading blogs after blogs about these issues and I don’t see an clean solution out there yet. Here is a list of blogs that talk about the very same issues that I listed above

I am doing research for a couple more days and if I can’t find anything clean solution to overcome these limitations, I am afraid Flex will not be used in this project. This is really disappointing!!

Drop me a note if you know any tips or tricks to overcome the limitations of HTTPService.

Advertisements
This entry was posted in Flex and tagged . Bookmark the permalink.

11 Responses to Flex Is Not Friendly To REST

  1. Your only real option is to implement your own HTTP classes using Socket or XMLSocket. Given that it sounds like you control your backend, serving up the appropriate cross domain policies via XML sockets shouldn’t be an issue.

  2. fantastic says:

    Thanks for the suggestion. I believe someone wrote such a class. The work around I came up seems to be working out.

  3. Joe says:

    If you are using the ATOM publishing protocol for your REST services you could consider using the GData batch extensions (http://code.google.com/apis/gdata/batch.html). This should mean that the information that would otherwise be in the header responses will be present in the XML payload instead and you only need a POST to get all jobs done… Might be worth a thought?

  4. fantastic says:

    Thanks for the suggestion. I will take a look at ATOM publishing protocol.

  5. Gnosior says:

    This is not directly related to Flex or its HttpService but a more general constraint imposed by the browser’s PluginAPI.

    Quote:
    https://bugs.adobe.com/jira/browse/SDK-11841
    Albert Chang @Adobe – [09/11/08 07:33 PM ]
    This is a problem with the browser community. The Flash Player team has sent the necessary source code to effectively communicate these http error messages to the flash player to the web browser community and have heard little to no response. Only Microsoft has responded so IE7 and IE8beta are the only browsers available that will not encounter this problem. Also, make sure to use the latest beta version of FP10.

    One workaround would be to use the ExternalInterface and get to the browser to RESTfully interact with the server.

  6. I have to say, that I could not agree with you in 100%, but that’s just my IMHO, which could be wrong.
    p.s. You have a very good template for your blog. Where have you got it from?

  7. ddavisso says:

    You need to use URLLoader/URLRequest/etc (part of the flash.net package).

    (1) Build your own HTTPClient.
    (2) Send headers & body in the body of the URLRequest to a PHP script that parses all the values and creates a real HTTP Request (e.g. prefix all headers with _h or something. Accept header would look like “_hAccept=text/xml”).
    (3) Have the URLLoader return raw data. You must then parse the entire thing into headers and body which can then be used by the application.
    (4) I have also developed my own AMF3Serializer and AMF3Deserializer and am sending all data over HTTP is AMF format. My server scripting is all PHP (use Zend).

  8. Guter Seite – Hätte da eine. Mein Ego ist auch unmittelbar dabei meinen Blog zu schreiben und ich finde dein Template klasse. Wo kann man das design installiert bekommen?

  9. Lest says:

    Someone has told me to stay away from httpservice, i can now imagine why just the HTTPService should be avoided. Just one reason. workaround would be nice.

  10. Mitul says:

    There is no need to use any library to overcome this problem.

    You just have to add one more header in your httpservice header like this :

    batchbookService.headers[‘X-HTTP-Method-Override’] = ‘DELETE’;
    Or
    batchbookService.headers[‘X-HTTP-Method-Override’] = ‘PUT’;

    It is working fine…
    I have found this recently….
    I was founding from two days…..

    • Cybian says:

      This is a good workaround for setting the delete and put http methods, but does not help with receiving http response status codes other than 200.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s