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.

6 Responses to “Flex Is Not Friendly To REST”

  1. Nathan de Vries Says:

    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. automotive jacks Says:

    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?

Leave a Reply