Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/boo1ean/app-service
Object methods decoration
https://github.com/boo1ean/app-service
Last synced: 30 days ago
JSON representation
Object methods decoration
- Host: GitHub
- URL: https://github.com/boo1ean/app-service
- Owner: boo1ean
- Created: 2014-10-28T13:36:22.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-27T13:17:30.000Z (over 9 years ago)
- Last Synced: 2024-08-09T14:32:30.062Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 184 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## app-service
Compose transforming, validation and actual service methods in a strict pipeline
## Installation
```
npm install app-service
```## Usage
Define transform, validate function and actual method and wire up it through app-service
```js
var build = require('app-service');function transformCreateUser (params) {
console.log('transform', params);params.email = params.email.toLowerCase();
return params;
}function validateCreateUser (params) {
console.log('validate', params):if (params.email.length > 100) {
throw new Error('Email is toooo long');
}
}function createUser (params) {
console.log(params);
return 'got it!';
}var service = build({
methods: { createUser: createUser },
validation: { createUser: validateCreateUser },
transforms: { createUser: transformCreateUser }
});service.createUser({ email: '[email protected]' }).then(function (result) {
console.log(result);
});
```outputs:
```
transform { email: '[email protected]' }
validate { email: '[email protected]' }
{ email: '[email protected]' }
got it!
```## LICENSE
MIT