0.1.4 • Published 7 years ago

yokto v0.1.4

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

yokto

An HTTP library so minimal, it is barely visible!

example

const http  = require('http')

const {stack, route, finalizer} = require('yokto');

http.createServer(stack([
  route.get('/ping', request => finalizer.end(200, 'pong'))
], function(request, error) {
  // this is an optional error handler
  if (error) {
    return finalizer.end(500, error.stack);
  }
  return finalizer.notFound();
})).listen(8000);

Example with async/await:

const http  = require('http')
const {stack, route, finalizer} = require('yokto');
const getRawBody = require('raw-body');

http.createServer(stack([
	route.post('/product', async function(request) {
		const body = JSON.parse(await getRawBody(request, 'utf8'));

		if (body.message === 'Hello') {
			return finalizer.end(200, JSON.stringify({ ok: true }));
		}

		return finalizer.end(500, 'Error');
	})
], function(request, error) {
  // this is an optional error handler
  if (error) {
    return finalizer.end(500, error.stack);
  }
  return finalizer.notFound();
})).listen(8000);

License

MIT

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

8 years ago

0.1.0

8 years ago