Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/evheniy/yeps
Yet Another Event Promised Server
https://github.com/evheniy/yeps
async await http http-server nodejs promise
Last synced: 9 days ago
JSON representation
Yet Another Event Promised Server
- Host: GitHub
- URL: https://github.com/evheniy/yeps
- Owner: evheniy
- License: mit
- Created: 2017-02-11T10:49:05.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-15T15:28:16.000Z (about 7 years ago)
- Last Synced: 2024-12-12T01:11:18.917Z (14 days ago)
- Topics: async, await, http, http-server, nodejs, promise
- Language: JavaScript
- Homepage:
- Size: 36.1 KB
- Stars: 16
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yet Another Event Promised Server
Simple promised node http request-response handler
[![NPM](https://nodei.co/npm/yeps.png)](https://npmjs.org/package/yeps)
[![npm version](https://badge.fury.io/js/yeps.svg)](https://badge.fury.io/js/yeps)
[![Build Status](https://travis-ci.org/evheniy/yeps.svg?branch=master)](https://travis-ci.org/evheniy/yeps)
[![Coverage Status](https://coveralls.io/repos/github/evheniy/yeps/badge.svg?branch=master)](https://coveralls.io/github/evheniy/yeps?branch=master)
[![Linux Build](https://img.shields.io/travis/evheniy/yeps/master.svg?label=linux)](https://travis-ci.org/evheniy/)
[![Windows Build](https://img.shields.io/appveyor/ci/evheniy/yeps/master.svg?label=windows)](https://ci.appveyor.com/project/evheniy/yeps)[![Dependency Status](https://david-dm.org/evheniy/yeps.svg)](https://david-dm.org/evheniy/yeps)
[![devDependency Status](https://david-dm.org/evheniy/yeps/dev-status.svg)](https://david-dm.org/evheniy/yeps#info=devDependencies)
[![NSP Status](https://img.shields.io/badge/NSP%20status-no%20vulnerabilities-green.svg)](https://travis-ci.org/evheniy/yeps)[![Known Vulnerabilities](https://snyk.io/test/github/evheniy/yeps/badge.svg)](https://snyk.io/test/github/evheniy/yeps)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/evheniy/yeps/master/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/evheniy/yeps.svg)](https://github.com/evheniy/yeps/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/evheniy/yeps.svg)](https://github.com/evheniy/yeps/network)
[![GitHub issues](https://img.shields.io/github/issues/evheniy/yeps.svg)](https://github.com/evheniy/yeps/issues)
[![Twitter](https://img.shields.io/twitter/url/https/github.com/evheniy/yeps.svg?style=social)](https://twitter.com/intent/tweet?text=Wow:&url=%5Bobject%20Object%5D)
## How to installnpm i -S yeps
## How to use
#### app.js
const App = require('yeps');
const app = module.exports = new App();
app.then(async (ctx) => {
ctx.res.statusCode = 200;
ctx.res.setHeader('Content-Type', 'application/json');
ctx.res.end('{"status":"OK"}');
});
app.catch(async (error, ctx) => {
ctx.res.statusCode = 500;
ctx.res.setHeader('Content-Type', 'application/json');
ctx.res.end(JSON.stringify({ error }));
});#### bin/www
#!/usr/bin/env node
const http = require('http');
const app = require('../app');http
.createServer(app.resolve())
.listen(parseInt(process.env.PORT || '3000', 10));
#### package.json"scripts": {
"start": "node bin/www"
}
## Breaking chainapp.then(async (ctx) => {
ctx.res.statusCode = 200;
ctx.res.setHeader('Content-Type', 'application/json');
ctx.res.end('{"status":"OK"}');
return Promise.reject();
}).then(async () => {
// it won't work
}).catch(async () => {
// it won't work
});
## Using routernpm i -S yeps-router
#### app.jsconst App = require('yeps');
const Router = require('yeps-router');
const app = module.exports = new App();
const router = new Router();
router.get('/').then(async (ctx) => {
ctx.res.statusCode = 200;
ctx.res.setHeader('Content-Type', 'application/json');
ctx.res.end('{"status":"OK"}');
});
app.then(router.resolve());
## Using servernpm i -S yeps-server
#### bin/www#!/usr/bin/env node
const server = require('yeps-server');
const app = require('../app');
server.createHttpServer(app);
## Error handlernpm i -S yeps-error yeps-logger
#### app.jsconst App = require('yeps');
const error = require('yeps-error');
const logger = require('yeps-logger');
const app = module.exports = new App();
app.all([
error(),
logger(),
]);
#### [YEPS documentation](http://yeps.info/)