sonde
v1.0.1
Published
A functional approach for API integration.
Downloads
1
Readme
A functional approach for API integration.
Usage Backend
const sonde = require("sonde");
sonde.hello = () => {
return {
message: "world";
};
};
sonde.greetings = (name) => {
return `Greetings ${name}. This is from Sonde or in english, Probe.`
}
// With Express Framework, but feel free to use anything you want.
// Express Setup here. BodyParser is required to parse the body into JSON.
app.get("/sondeapi", (req, res) => {
res.json(sonde(req.body.name, ...req.body.args));
// req.body.name : name of the "function" called.
// req.body.args : arguments of the "function" called.
});
Usage Frontend
<!-- in the head -->
<script src="https://cdn.jsdelivr.net/gh/STR1Z/sonde/frontend/sonde.js"></script>
<!-- fetching from the backend -->
<h1 sonde="hello">{{hello.message}}</h1>
<!-- "hello" is the "function" name. -->
// in javascript code...
sonde("greetings", "George").then((res) => console.log(res));
// Hooray for Promises