0.4.0 • Published 7 years ago

postfunction v0.4.0

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

postfunction

A basic npm module used to quickly develop Node.js libraries and functions by exposing them through a webserver, easily allowing you to check it's return value with given arguments. Idea is to work well with pure functions.

Basic Usage

Require the module in the file you have your functions in and just startWith the functions passed in:

const postfunction = require('./index');


function isEven(number) {
    return number % 2 === 0 ? `${number} is even!` : `${number} is odd.`
}

function someAsync(firstName, lastName) {
    return Promise.resolve(`Hello ${firstName} ${lastName}!`);
}

function greeting(firstName, lastName) {
    return someAsync(firstName, lastName);
}

postfunction.startWith(isEven, greeting);
...

The server starts on a random port and the following is logged in the app's console:

postFunction Server listening on port: 53883

Now just POST your arguments to http://localhost:port/functionName and have a look at your response!

Request:

{ "firstName": "John", "lastName": "Doe" }

Response:

{ "type": "promise<string>", "resolved": "Hello John Doe!", "rejected": null }

Magic!

Config

As of now, the only configuration available is the ability to define a port to start the server on. This is probably going to be useful.

postfunction.setPort(3000);

Todo

So far, only a regular JS object, type or Promise is supported. I would like the option to have the function run in a Node.js VM instance for pure functions to avoid side effects. A basic test has been written but please bare in mind this is pretty much the 'fist stab' at this so I'm sure it can be improved in may ways.

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago