The ImagineREST API provides the software, data, and services of Imagine's risk and portfolio management computational engine via the internet's predominant web service design model, REST. The REST API allows you to easily and transparently send requests to a cluster (farm) of one or more computational engines called compute servers. The compute server is the heart of Imagine's risk and portfolio management service.
The REST API leverages the Imagine Financial Platform (IFP) and its JavaScript execution environment and allows clients to expose IFP Apps, written in JavaScript, via a RESTful web service interface. The REST API and its interface provide a unified, scalable, modern, standards-compliant interface to Imagine's platform offering.
The Imagine REST API presents a simple RESTful web service interface. Users specify request and response messages in JSON (JavaScript Object Notation). Requests are dispatched based on their URIs.
You can interact with the Imagine REST API with a simple command line tool or using modern programming languages and tools.
To access the REST API, use https://api.derivatives.com/farm.
The examples available here assume the use of the tool cURL. User-supplied input is shown within angle brackets, i.e., < and >.
The REST API uses basic authentication over HTTPS. Users must provide an authorization token with every request.
A small set of resources are the gateway to a large set of features:
Starts a compute server and returns a JSON object with its id, name, and group.
Parameters |
|
name |
Optional. Defaults to id. |
group |
Optional. Defaults to "_anonymous". |
lp |
Optional. Defaults to "false". |
Notes |
The name and group pair must be unique in a given user's cluster. You can also pass the parameters as JSON in the body if you prefer. Parameters in the body override the parameters in the URI if both are passed, so if you pass name in both the body and the URI, the one in the body is used. |
curl -X POST -u
returns:
{
"id": "dbf4846a-6769-4b29-a68a-82adc9e0185a",
"name": "Analytics",
"group": "EQT"
"lp": true,
}
Returns in JSON the user, group name(s), or information about a specific node.
curl –X GET -u <user:pw> https://api.derivatives.com/farm/cluster
returns:
{
"owner": "john",
"nodes": [
{
"id": "dbf4846a-6769-4b29-a68a-82adc9e0185a",
"name": "Analytics",
"group": "EQT"
}
]
}
You can also list the active groups in your cluster:
curl –X GET –u <user:pw> https://api.derivatives.com/farm/cluster/groups
returns:
{
"groups": [
"RISKMGT",
"PORTMGT",
"_anonymous"
]
}
You must pass the node's id to stop it.
Embed the node id in the URL.
When you stop a node, it disconnects any process connected to it. The compute server may finish processing the request on which it it was working.
curl -X POST -u <user:pw> https://api.derivatives.com/farm/cluster/dbf4846a-6769-4b29-a68a-82adc9e0185a/stop
success returns:
{
"id": "dbf4846a-6769-4b29-a68a-82adc9e0185a"
}
curl -X DELETE -u <user:pw> https://api.derivatives.com/farm/cluster/dbf4846a-6769-4b29-a68a-82adc9e0185a
success returns:
{
"id": "dbf4846a-6769-4b29-a68a-82adc9e0185a"
}
An uncommon and valuable feature of Imagine's REST API is that you can author and deploy your own services using the IFP's rich primitives and the JavaScript programming language. Your cluster must have at least one node already running in it to use this resource.
Any IFP JavaScript function that follows certain conventions for calling and returning data can be called here. The function name must be exported, and the function should accept a "request" object. The function must return an object which is passed back to the caller as JSON. You cannot return a simple string or number, it must be an object.
When an app is invoked it is passed a "request" object. This object has two notable properties. The property "parameters" is populated from the query string in the URL. The property "body" is populated from the data passed by the POST command. You can see this demonstrated in Examples 2 and 3 below.
The following IFP JavaScript system.in and system.out objects are not available when accessed from the REST API.
Round trip to an IFP App.
curl –X GET -u <user:pw> https://api.derivatives.com/farm/app/hello/world
function world(request) {
return { value: "Hello World" };
}
exports['world'] = world
returns:
{
"value": "Hello World"
}
Passes data to the app using the query string. The data is provided in the "parameters" property of the request object.
curl –X GET -u <user:pw> https://api.derivatives.com/farm/app/echo/echo?say=hello
function echo(request) {
return request;
}
exports['echo'] = echo;
returns:
{
"body": null,
"id": "984d3dee-2317-4852-9300-585632115993",
"originalRequestId": null,
"parameters": {
"say": [
"hello"
]
},
"routing": "unicast",
"targetGroupName": null,
"targetNodeId": null,
"targetNodeName": null,
"type": "synchronous",
"uri": "/echo/echo"
}
Passes data to the app using a POST. The data is provided in the "body" property of the request object. You must pass the correct 'content-type' header. Currently, 'application/json' is available.
curl –X -H "content-type: application/json" POST -d '{"name":"ringo"}' -u <user:pw> https://api.derivatives.com/farm/app/echo/echo
function echo(request) {
return request;
}
exports['echo'] = echo;
returns:
{
"originalRequestId": null,
"targetNodeName": null,
"body":{
"name": "ringo"
},
"parameters": {
},
"id": "20420334-7099-4a9e-9955-d299fece927e",
"routing": "unicast",
"targetGroupName": null,
"uri":"/echo/echo",
"type":"synchronous",
"targetNodeId":null
}
As of this writing, the REST API uses a round-robin scheduling algorithm. It also offers the ability to route requests to specific nodes or groups of nodes. You might use this to optimize performance when particular data is loaded into a particular node. The REST API recognizes special HTTP extension headers that tell it to route requests to specific nodes or groups. You may send a request to a specific node by its id. You may send a request to a node in a collection of nodes by name or group.
Extension Request Headers |
|
Extension Request Headers |
Use these headers to specify which node the request should be sent to. |
X-Target-Node-Id |
Send the request to a specific node identified by UUID. |
X-Target-Node-Name |
Send the request to a node with this name. If you do not also specify "X-Target-Group-Name" the group will only look in the anonymous group. |
X-Target-Group-Name |
Send the request to any node with this group name. |
Extension Response Headers |
|
X-Request-Id |
The id of the request that was received. |
X-Response-Node-Id |
The id of the node that received the request. |
X-Target-Group-Name |
The name of the group that was requested and used. |
curl –X GET -u <user:pw> -H "X-Target-Node-Name:Analytics" https://api.derivatives.com/farm/app/echo/echo?say=hello
Errors from the REST API are returned as a JSON array.
{
"errors": [
{
"id": "ede6d706-115a-40b2-885f-da2c8090fdea",
"message": "No nodes exist in this cluster."
}
]
}
{
"errors": [
{
"file": "<unknown>",
"line": 0,
"message": "uncaught exception: your exception message here"
}
]
}
Q. When I try to run an app, why do I get the error, "No nodes exist in this cluster"?
A. You must first start a node (by POSTing to cluster) before you can use that node to invoke an app.
Q. When I try to start a node, why do I get the error "Unable to start compute server node"?
A. Error messages are currently being updated for greater clarity. In the meantime:
Q. When I try to run an app why do I get the error "No handler found. Please make sure the handler exists and is error free"?
A. There are three usual causes for this: