CORS Support for Orion Context Broker

May 27, 2015Tech

The latest release of Orion Context Broker (0.22) includes CORS support for GET requests. What that means in practice? It means that you can query context data from your Web App without having to develop a server-side component to act as a proxy for Orion.

How to activate it?

First you need to start Orion with the option '-corsOrigin'. That option allows you to specify what origins are allowed to query your Orion Context Broker. So if your application origin is http://www.example.com, then you should run contextBroker -corsOrigin http://www.example.com. If you do not know in advance what is going to be the origin of your app you can specify the special value '__ALL' . That would mean that any Web origin will be allowed to get data from your Orion Context Broker. 

This code snippet shows how would you query context by using XHR (AJAX).  

Future Work

What about other operations? Future releases of Orion Context Broker will allow to perform POST or DELETE operations following the same schema . Nonetheless, typically Web Apps would act as context data consumers and that's why we have given priority to GET requests. 

Related articles