Is it feasible to create a REST client with Flex?

2019-01-07 07:13发布

I'm starting a project using a Restful architecture implemented in Java (using the new JAX-RS standard)

We are planning to develop the GUI with a Flex application. I have already found some problems with this implementation using the HTTPService component (the response error codes, headers access...).

Any of you guys have some experience in a similar project. Is it feasible?

标签: java flex rest
15条回答
【Aperson】
2楼-- · 2019-01-07 07:39

There are definite shortcomings of Flex's ability to act as a pure RESTful client.

The comments below are from this blog:

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.

Matt Raible also gave a nice presentation on REST with Rails, Grails, GWT and Flex that have some good references linked from it.

Whether it's feasible or not really depends on how much your willing to work around by proxying, etc.

查看更多
我命由我不由天
3楼-- · 2019-01-07 07:43

The short answer is yes, you can do RESTful with Flex. You just have to work around the limitations of the Flash player (better with latest versions) and the containing browser's HTTP stack limitations.

We've been doing RESTful client development in Flex for more than a year after solving the basic HTTP request header and lack of PUT and DELETE via the rails-esque ?_method= approach. Tacky perhaps, but it gets the job done.

I noted some of the headers pain in an old blog post at http://verveguy.blogspot.com/2008/07/truth-about-flex-httpservice.html

查看更多
对你真心纯属浪费
4楼-- · 2019-01-07 07:44

Actually were are already using Flex with a Rest-Style Framework. As mbrevort already mentioned PUT and DELETE methods cannot be directly used. Instead we are doing PUT via a POST and for DELETE we are using a GET on a resource with an URL parameter like ?action=delete.

This is not 100% Rest style, so I am not sure, if this works with a JSR 311 implementation. You will need some flexbility on the server side to workaround the PUT and DELETE restrictions.

With regards to error handling, we have implemented an error service. In case of an server side error, the Flex application can query this error service to get the actual error message. This is also much more flexible than just mapping HTTP return codes to static messages.

However thanks To ECMA scripting of Flex working with XML based REST services is very easy.

查看更多
Ridiculous、
5楼-- · 2019-01-07 07:45

Yes, I was able to use POST and access headers with this component:

http://code.google.com/p/as3httpclient/wiki/Links

Example

查看更多
We Are One
6楼-- · 2019-01-07 07:47

The book Flexible Rails may be helpful -- It is an excellent resource on how to use Flex as a RESTful client. Although it focuses on using Flex with the Rails framework, I believe the concepts apply to any RESTful framework. I used this book to get up to speed quickly on using Flex with REST.

查看更多
Summer. ? 凉城
7楼-- · 2019-01-07 07:50

I'm working right now on an application that relies heavily on REST calls between Flex and JavaScript and Java Servlets. We get around the response error code problem by establishing a convention of a <status id="XXX" name="YYYYYY"> block that gets returned upon error, with error IDs that roughly map to HTTP error codes.

We get around the cross-site scripting limitations by using a Java Servlet as an HTTP proxy. Calls to the proxy (which runs on the same server that serves the rest of the content, including the Flex content, sends the request to the other server, then sends the response back to the original caller.

查看更多
登录 后发表回答