Iron.io Enhances Web and Mobile Capabilities with CORS Support
Iron.io adds CORS support |
Iron.io is pleased to announce the introduction of support for Cross-origin Resource Sharing (CORS). This capability means that developers have even easier access to the Iron.io platform from desktop and mobile browsers and other client devices.
Why CORS Matters with the Iron.io Platform
EnableCORS website |
Iron.io handles the scaling and execution of the tasks or the pushing of the message to another endpoint. Developers simply have to make calls to the Iron.io APIs and they get production-scale message queuing, task processing, and key/value data storage. Here's an example of how you might use CORS to connect to the Iron.io platform.
How CORS Works
Browser Support
You can view the full table of browser versions here.
Making a CORS Request for the Iron.io Platform
This section shows a simple example of how to make a cross-domain request in JavaScript to IronMQ. The project ID and OAuth token provide authentication.
// Create the XHR object. function createCORSRequest(method, url) { var xhr = new XMLHttpRequest(); xhr.open(method, url, true); return xhr; } // Insert your iron.io credentials here: var projectId = 'YOUR PROJECT ID'; var queueName = 'YOUR QUEUE NAME'; var token = 'YOUR TOKEN'; var url = 'https://mq-aws-us-east-1.iron.io/1/projects/' + projectId + '/queues/' + queueName + '/messages?oauth='+ token; // create a request and set content-type header var xhr = createCORSRequest('POST', url); // missing content-type header will lead to a 406 response xhr.setRequestHeader("Content-Type", "application/json"); // Parse the response in the format of a JSON string xhr.onload = function() { var text = xhr.responseText; var resp = JSON.parse(text) console.log("My message is: ", resp); }; xhr.onerror = function() { console.log('Woops, there was an error making the request.'); }; // Stringify your JSON request body xhr.send(JSON.stringify({"messages":[{"body":"your message"}]}));
Similar approaches can be used for queuing up a worker or putting an item into a cache in Iron.io except with different endpoints, worker/cache names, methods, and payloads.
Note: The above example is primarily intended for as a demonstration given that the project ID and token are exposed within the JavaScript code. We will be creating additional resources on how to connect in a more secure manner.
Visit the Iron.io Dev Center for a complete list of API methods for the services.
IronMQ API reference |
To learn more about how Iron.io can help you process messages, run tasks and store key/value pairs using from desktop and mobile clients, visit Iron.io today.
How can I queue a worker task from client-side javascript without exposing the project_id and OAuth token?