Arupex is a Serverless/Server framework for NodeJS It allows you to build a serverless application for your needs, but also allows you to wrap that with a http server if need be
- Making Testing easier on Developers
- Making Mocking a thing of the past
- Simplifying Workflows
- Making Dependency Injection simple and elegant
- Hooks
- DataServices
- DataServiceUtils
- Service
- Policies
- Functions
Examples - download example project
- This is where you put configuration data for things like data services (connection strings)
- For instances if you have a CurrencyDataService you might have the following configuration
Example:
module.exports = {
CurrencyDataService : {
baseUrl : 'http://api.fixer.io/',
respondWithProperty: 'rates'
}
};
Routes allows you to have a http server associated with your serverless functions our route syntax allows you to include parameters in the route both {{required}} and {optional parameters} which will be automatically injected into the 'event' of your function
module.exports = {
'/api/v1/ping?locale={{locale}}&time={optionalTime}' : 'FunctionName'
};
// Note that currencyConversion is a Service and res is a container for responses, these are injected by name
module.exports = function(currencyConversion, res){
currencyConversion.getRates().then((data) => {
res.ok(data);
}, (err) => {
res.badRequest(err);
});
};
//useful for abstracting event, or creating loggers, or other things you might need injected into DataService
module.exports = function(event, context){
return {
getUserId : () => { return event.userId; }
};
};
A common use for hooks is to allow injection of external libraries
//in a hook file called moment.js
module.exports = function(){
return require('moment');
}
//works similarly to express middlware, however you can inject hooks/services
module.exports = function(req, res, next, iamService, userHook){
iamService.auth(userHook.getUserId()).then((userData) => {
userHook.setData(userData);
next();
}).catch(() => {
res.fail();
});
};
//creates a service which takes in a CurrencyDataService and a UserDataService
module.exports = function(CurrencyDataService, UserDataService){
function getRates(){
return CurrencyDataService.getLatestBase({ base : UserDataService.getOtherCurrency() });
}
return {
getRates : getRates
};
};
module.exports = [
{ getLatestBase : 'GET latest?base={{base}}' },//you can force the output function name
'latest?symbols={{symbols}}'//you can let clientBuilder determine the name of the function
];
//allows you to determine values for variables via other injectable services
module.exports.injector = function(context, UserService){
return {
baseUrl : 'http://api.fixer.io/',
base: UserService.getCurrency(),
symbols : UserService.getOtherCurrency()
};
};
module.exports = {
getCurrency : function (){
return 'USD';
},
getOtherCurrency : function(){
return 'JPY';
}
};
//cannot be mocked
module.exports.overrideable = false;
Responses - are an abstraction for the underlying callback it be a callback to AWS lambda/Gateway or to NODE.js http socket
Workers are great if you want a task to happen asynchronously in the background without user/client triggering if you wanted to create a 'cron' worker you would go about this similarly to
Example:
module.exports = function() {
let now = new Date();
if(now.getHour() === 6 && now.getMinute() === 30) {//only acts at 6:30 am
//do things
}
};
module.exports.interval = 60000;//every minute
Arupex simplifies the mocking process by generating mocks for you based on a schema generated from your actual code!