cealloga
Ceallóga are simple ES6 arrow functions. Validate, test, and publish them as web service endpoints, and do it all via an easy-to-use rest API.
Requirements
Install
npm install -g cealloga
Run
cealloga
Getting started
In this tutorial, we'll create a microservice that:
- takes information from a raw data source called
colours
- sums the colours up and returns them as an object called
chartData
(something you might later consume in an UI component such as a bar chart, for example.)
Before we begin, let's dissect the uncompressed source code we want to host as a web service.
{ let colours = ceallogvarscolours // A list of colours, POSTed by the user in the request body. coloursMap = {} // A map of colours, where key will be colour name ('yellow') and value a total (`2`). chartData = labels: series: // Chart data to build from incoming colours if colours // Sum the colours... colours; for var name in coloursMap // Push the `name` into labels and `total` into series in the same order. let total = coloursMapname; chartDatalabels; chartDataseries; return chartData;}
Validate
We create our code by first posting it to the /code/validate
service. When we
do this, the request is validated, the code is compiled, it's added to the
database and cached on the server, and finally we receive a response with some
information about it.
- Save the following file as
barchart.json
.
- In a terminal, run this curl command from the same directory as
barchart.json
:
curl -H "Content-Type: application/json" -X POST -d @barchart.json http://localhost:3000/code/validate
You should now have a response like the following. Copy the "service"
value;
you'll need it in the next example!
Test
Now that the code has been validated and created, let's send it some colour data and test the results.
- Save the following file as
colours.json
.
- In a terminal, run this curl command from the same directory as
colours.json
:
curl -H "Content-Type: application/json" -X POST -d @colours.json http://localhost:3000/cealloga/_test/5a610660158ffae3135b7c7e # <- replace with your _test endpoint from the validate example
If you're seeing the following, it worked!
Publish
Once we're happy with the test results, we can publish the function by name as
/cealloga/barchart
.
Run the following curl command.
curl http://localhost:3000/code/publish/5a610660158ffae3135b7c7e # <- replace with the id from the validate example
You should get a response like the following:
Making a request to the published endpoint
The only thing left to day at this point is to check that /cealloga/barchart
is up and running.
In a terminal, run this curl command from the same directory as colours.json
:
curl -H "Content-Type: application/json" -X POST -d @colours.json http://localhost:3000/cealloga/barchart
As in the test example above, if you're seeing the following, it worked again!