Skip to content

Instantly share code, notes, and snippets.

@richorama
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richorama/e44f07bbe13ee12d221b to your computer and use it in GitHub Desktop.
Save richorama/e44f07bbe13ee12d221b to your computer and use it in GitHub Desktop.
Experimental generic http interface for Codename Orleans
/*
Experimental generic http interface for Codename Orleans
To use, POST to this url:
POST /grainType/grainId/grainMethod
[arg1, arg2]
grain response will be in the http response body
with cURL:
$ curl -H "Content-Type: application/json" -d "[\"aString\", 123, true]" http://localhost:8080/Grain1/1/SetValues/
All grains must return a value
To install type:
$ npm install express node-orleans body-parser
Then replace the values for grainDll and grainNamespace.
Ensure the necessary files are in place, as desribed here: https://github.com/OrleansContrib/node-orleans#installation
To run type:
$ node server
*/
var orleans = require('node-orleans');
var client = orleans({
grainDll : "MyGrainInterfaces.dll", // the assembly containing your grain interfaces
grainNamespace : "MyGrainInterfaces" // the namespace of your grain interfaces
});
var express = require('express');
var bodyParser = require('body-parser')
var app = express();
app.use(bodyParser.json())
app.post("/:grainType/:grainId/:grainMethod/", function(req, res){
var grainId = req.params.grainId;
if (!(req.params.grainId.indexOf("-") > 0)){
grainId = parseInt(req.params.grainId);
}
client.call(req.params.grainType, grainId, req.params.grainMethod, req.body, function(err, result){
res.json(result);
});
});
client.init(function(){
app.listen(8080);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment