All Projects → serviejs → throwback

serviejs / throwback

Licence: MIT License
An asynchronous middleware pattern

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to throwback

react-koa-universal
a boilerplate react graphql apollo css-in-js buzzword koa ssr pwa wasm throwaway app 🚮
Stars: ✭ 12 (-52%)
Mutual labels:  koa
Movie-Paradise
A responsive movie preview web app
Stars: ✭ 19 (-24%)
Mutual labels:  koa
json-error
Error handler for pure-JSON apps
Stars: ✭ 84 (+236%)
Mutual labels:  koa
Retrogamer-Compose
Retro games implemented using Jetpack Compose
Stars: ✭ 113 (+352%)
Mutual labels:  compose
coolliyong.github.io
javascript基础
Stars: ✭ 57 (+128%)
Mutual labels:  koa
koa2-rest-scaffold
Koa2 RESTful API 脚手架。
Stars: ✭ 27 (+8%)
Mutual labels:  koa
node-fs
node-fs
Stars: ✭ 55 (+120%)
Mutual labels:  koa
kurier
TypeScript framework to create JSON:API compliant APIs
Stars: ✭ 30 (+20%)
Mutual labels:  koa
Smart-courier-cabinet
智能快递柜小程序+nodejs koa2后端
Stars: ✭ 21 (-16%)
Mutual labels:  koa
servie
Standard, framework-agnostic HTTP interfaces for JavaScript servers and clients
Stars: ✭ 39 (+56%)
Mutual labels:  servie
koa-server
🗄️ GraphQL Back-end Server with Relay, Koa, MongoDB and Mongoose
Stars: ✭ 31 (+24%)
Mutual labels:  koa
normalize-text
📝 Provides a simple API to normalize texts, whitespaces, paragraphs & diacritics.
Stars: ✭ 54 (+116%)
Mutual labels:  compose
node-input-validator
Validation library for node.js
Stars: ✭ 74 (+196%)
Mutual labels:  koa
inversify-koa-utils
inversify-koa-utils is a module based on inversify-express-utils. This module has utilities for koa 2 applications development using decorators and IoC Dependency Injection (with inversify)
Stars: ✭ 27 (+8%)
Mutual labels:  koa
koa-vue-view
A Koa view engine which renders Vue components on server.
Stars: ✭ 29 (+16%)
Mutual labels:  koa
datmusic-android
Music search, downloader & player app using Jetpack Compose
Stars: ✭ 448 (+1692%)
Mutual labels:  compose
restria
Entria's REST API boilerplate
Stars: ✭ 25 (+0%)
Mutual labels:  koa
koa-yield-breakpoint
Add breakpoints around `yield` expression especially for koa@1.
Stars: ✭ 17 (-32%)
Mutual labels:  koa
breakout-compose
Breakout clone built with Compose
Stars: ✭ 27 (+8%)
Mutual labels:  compose
store-server
vue-store项目后端。基于Node.js(Koa)实现的电商后端项目。
Stars: ✭ 199 (+696%)
Mutual labels:  koa

Throwback

NPM version NPM downloads Build status Test coverage

Simple asynchronous middleware pattern.

Installation

npm install throwback --save

Usage

Compose asynchronous (promise-returning) functions.

const { compose } = require("throwback");

const fn = compose([
  async function(ctx, next) {
    console.log(1);

    try {
      await next();
    } catch (err) {
      console.log("throwback", err);
    }

    console.log(4);
  },
  async function(ctx, next) {
    console.log(2);

    return next();
  }
]);

// Callback runs at the end of the stack, before
// the middleware bubbles back to the beginning.
fn({}, function(ctx) {
  console.log(3);

  ctx.status = 404;
});

Tip: In development (NODE_ENV !== "production"), compose will throw errors when you do something unexpected. In production, the faster non-error code paths are used.

Example

Build a micro HTTP server!

const { createServer } = require("http");
const finalhandler = require("finalhandler"); // Example only, not compatible with single `ctx` arg.
const { compose } = require("throwback");

const app = compose([
  function({ req, res }, next) {
    res.end("Hello world!");
  }
]);

createServer(function(req, res) {
  return app({ req, res }, finalhandler());
}).listen(3000);

Use Cases

Inspiration

Built for servie and inspired by koa-compose.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].