# qpi

> A simple yet relatively powerful http server framework

Latest version **0.1.0** (published 2019-11-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install qpi
pnpm add qpi
yarn add qpi
bun add qpi
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2019-11-27 |
| First published | 2019-11-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 189.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | qfoooo |
| Maintainers | qfoooo |
| Keywords | server, api, cors, http |

## Links

- npm: https://www.npmjs.com/package/qpi
- Repository: https://github.com/qfoooo/qpi
- Homepage: https://github.com/qfoooo/qpi#readme
- Issues: https://github.com/qfoooo/qpi/issues
- npm.io page: https://npm.io/package/qpi

## Dependencies (2)

- [restify](https://npm.io/package/restify.md) ^8.4.0
- [restify-cors-middleware](https://npm.io/package/restify-cors-middleware.md) ^1.1.1

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2019-11-27
- 0.0.1 — 2019-11-05
- 0.0.0 — 2019-11-04

## README

QPI
===

Yet another http framework for NodeJS

[Documentation](https://qfoooo.github.io/qpi/)


# Quick Start

```js
const Server = require("qpi")

const server = new Server({
  body: true,       // enable body parser
  query: true,      // enable query parser
  cors: {
    origins: ["*"]  // allow every origin
  }
})

server.get("/", Q => Q.send("Hello, World!"))
server.get("/hello/:you", Q => Q.send(`Hello, ${Q.param.you}!`))
// GET /hello/bob => Hello, bob!

server.post("/greet", Q => Q.send(`${Q.body.greet}, ${Q.query.me}!`))
// POST /greet?me=Bob -d greet=Hi
// => Hi, Bob!

server.post("/",
  // retrieves the token passed in the authorization header
  async Q => Q.next({token: await Token.find({token: Q.header.Authorization})}),
  // If the token is falsy, send a 401 unauthorized else, call next handler
  Q => Q.$token && Q.next() || Q.unauthorized(),
  // valiates the query and attach what was validated to the context
  Q => Q.next({...(myValidationMiddleware()(Q))}),
  // do stuff
  Q => Q.send({
    say: Q.$say, // populated by the custom validation middleware,
    to: Q.$token.user.name, // fetch by the 1st step
  })
)
// POST / -d "say=   Aloha~   " -H "Authorization: 5up3r5ekr37"
// => {say: "Aloha~", to: "Bob"}
```

One can also inject its own return methods:

```js
const Server = require("qpi")

const server = new Server({
  extend: {
    toInifinity: Q => () => Q.send("And Beyond"),   // add a new response
    internalServerError: Q => e: Error => {         // override an existing response
      if (process.env.NODE_ENV === "development")
        return Q.end(500, {code: "InternalServerError", message: e.message, stack: e.stack})
      return Q.end(500, {code: "InternalServerError", message: "Something went wrong"})
    }
  }
})

server.get("/infinity", Q => Q.toInfinity())
// GET /infinity
// => "And beyond"

server.get("/", () => { throw new Error("foo") })

// GET /
// => { code: "InternalServerError", message: "foo", stack: "..." }
```


# Contributing

## Yarn commands

- **test**: Run tests + coverage
- **lint**: Run linter (`yarn lint --fix` to fix some errors)
- **doc**: Generate JSDoc documentation

---
_Source: https://npm.io/package/qpi · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
