REST CORS

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

REST CORS

Simon Walter
Hi all,

I'm trying to decide on an web service API structure. Ideally I'd like
it to be in the REST style. I've played around with qx.io.rest.Resource
and it works. However, I cannot see a way to specify a different server.
Yes I'd like to be able to have the REST service on a different server
from the one that serves the qooxdoo app.

Is this possible? It looks like it's possible with a plain
qx.io.request.Xhr. Jsonp does work as well, but I cannot see a way to
specify the method when using qx.io.request.Jsonp.

Must I use a qx.io.request.Xhr? Are there any other ways to do this? As
I'm in the initial stages, I am very open to any suggestions.

Thanks,

Simon

PS
If there are currently no plans to allow qx.io.rest.Resource to do CORS,
I would highly recommend it.

--
simonsmicrophone.com


------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: REST CORS

MartinWittemann
Administrator
Hello,
When having the REST service on another machine, you have to use either JSONP or CORS. I'm not the export in that area but as far as I know, CORS is not supported by all browsers.
Nevertheless, I forwarded you mail to the author of our REST and io layer which can give you some more details. He will be back on monday.
Regards,
Martin


> Hi all,
>
> I'm trying to decide on an web service API structure. Ideally I'd like
> it to be in the REST style. I've played around with qx.io.rest.Resource
> and it works. However, I cannot see a way to specify a different server.
> Yes I'd like to be able to have the REST service on a different server
> from the one that serves the qooxdoo app.
>
> Is this possible? It looks like it's possible with a plain
> qx.io.request.Xhr. Jsonp does work as well, but I cannot see a way to
> specify the method when using qx.io.request.Jsonp.
>
> Must I use a qx.io.request.Xhr? Are there any other ways to do this? As
> I'm in the initial stages, I am very open to any suggestions.
>
> Thanks,
>
> Simon
>
> PS
> If there are currently no plans to allow qx.io.rest.Resource to do CORS,
> I would highly recommend it.
>
> --
> simonsmicrophone.com
>
>
> ------------------------------------------------------------------------------
> For Developers, A Lot Can Happen In A Second.
> Boundary is the first to Know...and Tell You.
> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
> http://p.sf.net/sfu/Boundary-d2dvs2
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: REST CORS

Simon Walter
Thank you Martin. I understand about CORS and browser support. That is
always a concern.

It looks like qx.io.request.Jsonp does not inherit from
qx.io.remote.Request, and so there is no setMethod() method. However,
qx.io.request.Xhr has a setMethod() method. I think a setMethod() method
for qx.io.request.Jsonp would enable us to make REST style services
available to other servers. Currently one cannot specify the HTTP METHOD
when using qx.io.request.Jsonp. So it's not possible to use this for a
REST style service, as everything will be either GET or POST - I assume.
We'll need PUT and DELETE as well.

I'm interested in qx.io.rest.Resource, as it seems to work quite well
and is very straight forward to use.

I'm just getting started with qooxdoo and OO JS, but if there is
anything I can do to help with this, please let me know.

Many thanks,

Simon

On 04/13/2012 06:03 PM, Martin Wittemann wrote:

> Hello,
> When having the REST service on another machine, you have to use either JSONP or CORS. I'm not the export in that area but as far as I know, CORS is not supported by all browsers.
> Nevertheless, I forwarded you mail to the author of our REST and io layer which can give you some more details. He will be back on monday.
> Regards,
> Martin
>
>
>> Hi all,
>>
>> I'm trying to decide on an web service API structure. Ideally I'd like
>> it to be in the REST style. I've played around with qx.io.rest.Resource
>> and it works. However, I cannot see a way to specify a different server.
>> Yes I'd like to be able to have the REST service on a different server
>> from the one that serves the qooxdoo app.
>>
>> Is this possible? It looks like it's possible with a plain
>> qx.io.request.Xhr. Jsonp does work as well, but I cannot see a way to
>> specify the method when using qx.io.request.Jsonp.
>>
>> Must I use a qx.io.request.Xhr? Are there any other ways to do this? As
>> I'm in the initial stages, I am very open to any suggestions.
>>
>> Thanks,
>>
>> Simon
>>
>> PS
>> If there are currently no plans to allow qx.io.rest.Resource to do CORS,
>> I would highly recommend it.
>>
>> --
>> simonsmicrophone.com
>>
>>
>> ------------------------------------------------------------------------------
>> For Developers, A Lot Can Happen In A Second.
>> Boundary is the first to Know...and Tell You.
>> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
>> http://p.sf.net/sfu/Boundary-d2dvs2
>> _______________________________________________
>> qooxdoo-devel mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>
> ------------------------------------------------------------------------------
> For Developers, A Lot Can Happen In A Second.
> Boundary is the first to Know...and Tell You.
> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
> http://p.sf.net/sfu/Boundary-d2dvs2
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


--
simonsmicrophone.com

------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: REST CORS

Tristan Koch
Hi Simon,

rest.Resource uses io.request.Xhr internally, so you can do CORS with rest.Resource. Note you need to configure your server to set appropriate HTTP headers [1].

You can use rest.Resource with io.request.Jsonp by sub classing and overriding _getRequest(). The problem with JSONP, however, is that you always send GET requests in terms of HTTP. This is because JSONP works by adding a script tag pointing to the resource. Script tags cause a GET request. Also, there is no reliable way to send large amounts of data and no custom headers can be set.

In theory, its possible to emulate REST with JSONP, sending method and headers as part of the payload. But this requires custom modifications of the backend. In short, using io.request.Xhr is very much recommended. For browsers not supporting CORS you can try one of the polyfills floating around lately (adding fallbacks to qooxdoo is already planned).

Regards
Tristan

[1] https://developer.mozilla.org/en/http_access_control

Am 13.04.2012 um 11:27 schrieb Simon Walter:

> Thank you Martin. I understand about CORS and browser support. That is
> always a concern.
>
> It looks like qx.io.request.Jsonp does not inherit from
> qx.io.remote.Request, and so there is no setMethod() method. However,
> qx.io.request.Xhr has a setMethod() method. I think a setMethod() method
> for qx.io.request.Jsonp would enable us to make REST style services
> available to other servers. Currently one cannot specify the HTTP METHOD
> when using qx.io.request.Jsonp. So it's not possible to use this for a
> REST style service, as everything will be either GET or POST - I assume.
> We'll need PUT and DELETE as well.
>
> I'm interested in qx.io.rest.Resource, as it seems to work quite well
> and is very straight forward to use.
>
> I'm just getting started with qooxdoo and OO JS, but if there is
> anything I can do to help with this, please let me know.
>
> Many thanks,
>
> Simon
>
> On 04/13/2012 06:03 PM, Martin Wittemann wrote:
>> Hello,
>> When having the REST service on another machine, you have to use either JSONP or CORS. I'm not the export in that area but as far as I know, CORS is not supported by all browsers.
>> Nevertheless, I forwarded you mail to the author of our REST and io layer which can give you some more details. He will be back on monday.
>> Regards,
>> Martin
>>
>>
>>> Hi all,
>>>
>>> I'm trying to decide on an web service API structure. Ideally I'd like
>>> it to be in the REST style. I've played around with qx.io.rest.Resource
>>> and it works. However, I cannot see a way to specify a different server.
>>> Yes I'd like to be able to have the REST service on a different server
>>> from the one that serves the qooxdoo app.
>>>
>>> Is this possible? It looks like it's possible with a plain
>>> qx.io.request.Xhr. Jsonp does work as well, but I cannot see a way to
>>> specify the method when using qx.io.request.Jsonp.
>>>
>>> Must I use a qx.io.request.Xhr? Are there any other ways to do this? As
>>> I'm in the initial stages, I am very open to any suggestions.
>>>
>>> Thanks,
>>>
>>> Simon
>>>
>>> PS
>>> If there are currently no plans to allow qx.io.rest.Resource to do CORS,
>>> I would highly recommend it.
>>>
>>> --
>>> simonsmicrophone.com
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> For Developers, A Lot Can Happen In A Second.
>>> Boundary is the first to Know...and Tell You.
>>> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
>>> http://p.sf.net/sfu/Boundary-d2dvs2
>>> _______________________________________________
>>> qooxdoo-devel mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>>
>>
>> ------------------------------------------------------------------------------
>> For Developers, A Lot Can Happen In A Second.
>> Boundary is the first to Know...and Tell You.
>> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
>> http://p.sf.net/sfu/Boundary-d2dvs2
>> _______________________________________________
>> qooxdoo-devel mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>
> --
> simonsmicrophone.com
>
> ------------------------------------------------------------------------------
> For Developers, A Lot Can Happen In A Second.
> Boundary is the first to Know...and Tell You.
> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
> http://p.sf.net/sfu/Boundary-d2dvs2
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: REST CORS

Simon Walter
Hi Tristan,

Thanks for the info.

I must have been setting the URL incorrectly last time I tried. Because
now it works!. I'm building a custom server with PION, rapidjson, and
soci. So I've already set up the HTTP headers.

As far as making requests is concerned, would this be a correct way to
go about it? I'm not really sure about qx.data.store.Rest. I read
somewhere that qx.ui.table.Table does not have a way to bind to the
stores yet.

var dataService = {"get": { method: "GET", url: "/reservations" }};
var dataResource = new qx.io.rest.Resource(dataService);
dataResource.setBaseUrl("http://devserver:8080/rest");

dataResource.addListener("getSuccess", function(e) {
                 var data = e.getData();
                 tableModel.setData(data.rows);
             });
dataResource.get();

Any other tips are welcome. Though, this is working well already! Thank
you very much!

Simon

On 04/16/2012 11:09 PM, Tristan Koch wrote:

> Hi Simon,
>
> rest.Resource uses io.request.Xhr internally, so you can do CORS with rest.Resource. Note you need to configure your server to set appropriate HTTP headers [1].
>
> You can use rest.Resource with io.request.Jsonp by sub classing and overriding _getRequest(). The problem with JSONP, however, is that you always send GET requests in terms of HTTP. This is because JSONP works by adding a script tag pointing to the resource. Script tags cause a GET request. Also, there is no reliable way to send large amounts of data and no custom headers can be set.
>
> In theory, its possible to emulate REST with JSONP, sending method and headers as part of the payload. But this requires custom modifications of the backend. In short, using io.request.Xhr is very much recommended. For browsers not supporting CORS you can try one of the polyfills floating around lately (adding fallbacks to qooxdoo is already planned).
>
> Regards
> Tristan
>
> [1] https://developer.mozilla.org/en/http_access_control
>
> Am 13.04.2012 um 11:27 schrieb Simon Walter:
>
>> Thank you Martin. I understand about CORS and browser support. That is
>> always a concern.
>>
>> It looks like qx.io.request.Jsonp does not inherit from
>> qx.io.remote.Request, and so there is no setMethod() method. However,
>> qx.io.request.Xhr has a setMethod() method. I think a setMethod() method
>> for qx.io.request.Jsonp would enable us to make REST style services
>> available to other servers. Currently one cannot specify the HTTP METHOD
>> when using qx.io.request.Jsonp. So it's not possible to use this for a
>> REST style service, as everything will be either GET or POST - I assume.
>> We'll need PUT and DELETE as well.
>>
>> I'm interested in qx.io.rest.Resource, as it seems to work quite well
>> and is very straight forward to use.
>>
>> I'm just getting started with qooxdoo and OO JS, but if there is
>> anything I can do to help with this, please let me know.
>>
>> Many thanks,
>>
>> Simon
>>
>> On 04/13/2012 06:03 PM, Martin Wittemann wrote:
>>> Hello,
>>> When having the REST service on another machine, you have to use either JSONP or CORS. I'm not the export in that area but as far as I know, CORS is not supported by all browsers.
>>> Nevertheless, I forwarded you mail to the author of our REST and io layer which can give you some more details. He will be back on monday.
>>> Regards,
>>> Martin
>>>
>>>
>>>> Hi all,
>>>>
>>>> I'm trying to decide on an web service API structure. Ideally I'd like
>>>> it to be in the REST style. I've played around with qx.io.rest.Resource
>>>> and it works. However, I cannot see a way to specify a different server.
>>>> Yes I'd like to be able to have the REST service on a different server
>>>> from the one that serves the qooxdoo app.
>>>>
>>>> Is this possible? It looks like it's possible with a plain
>>>> qx.io.request.Xhr. Jsonp does work as well, but I cannot see a way to
>>>> specify the method when using qx.io.request.Jsonp.
>>>>
>>>> Must I use a qx.io.request.Xhr? Are there any other ways to do this? As
>>>> I'm in the initial stages, I am very open to any suggestions.
>>>>
>>>> Thanks,
>>>>
>>>> Simon
>>>>
>>>> PS
>>>> If there are currently no plans to allow qx.io.rest.Resource to do CORS,
>>>> I would highly recommend it.


--
simonsmicrophone.com

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel