# relay.ts

> Performant webserver framework with a familiar API

Latest version **1.0.1** (published 2018-11-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install relay.ts
pnpm add relay.ts
yarn add relay.ts
bun add relay.ts
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-11-11 |
| First published | 2018-11-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 131.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Harry |
| Maintainers | hjfitz |
| Keywords | typescript server, alternative, typescript, webserver, framework, connect, express, restful, server, https, rest, http, crud, api |

## Links

- npm: https://www.npmjs.com/package/relay.ts
- Repository: https://github.com/hjfitz/relay.ts
- Homepage: https://github.com/hjfitz/relay.ts#readme
- Issues: https://github.com/hjfitz/relay.ts/issues
- npm.io page: https://npm.io/package/relay.ts

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) ^3.1.0
- [mime-types](https://npm.io/package/mime-types.md) ^2.1.21

## 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

- 1.0.1 (latest) — 2018-11-11
- 1.0.0 — 2018-11-09

## README

# relay.ts
> Serve RESTFul APIs quickly and simply

## What?
This project is an abstraction over the builtin HTTP(s) module in Node. It aims to emulate the Express.js API, whilst being *very* performant and almost entirely dependency free.

Currently, this library is in very early stages and used more as a learning experience.

## How does this differ from Express?
Express is based on Connect, which has the simple concept of: all middleware goes on a central stack. The stack of middleware is traversed and checking verb/url.

In relay, the `.init()` method organises middle in to different stacks, accessed via an object with the URL as a key. Each URL sits under each verb, which is the key, too:

```js
this.middlewares = {
  'GET': {
    '/': [Middleware, Middleware],
    '/api': [Middleware, Middleware],
    '*': [Middleware]
  },
  'POST': {
    '/api': [Middleware]
  }
}
```

As you can guess, middleware lookup is O(1), not O(N) worst case. **PERF**

## Usage
Once this is published on npm, install it!

```zsh
yarn add ${libname}
```

Then, create a server!

```ts
import path from 'path';
import relay, { useStatic } from 'relay';

const server: Server = relay.createServer({ port: 8080 });

// you can use HTTP verbs, and use - just like express!
server.get('/', (req, res) => {
  res.send('hello, world');
});

// static file hosting built in:
server.get(useStatic(path.join(__dirname, 'static')));

// you can also chain!
server.get('/baz', (req, res, next) => {
  delete req._req;
  res.json(req);
})
.post('/', (req, res) => {
  res.send('oi')
});

// make sure to call .init, to create the server!
server.init().then(() => console.log('listening on 8080'));
```

## Roadmap:
- [x] Body parsing (form, json, urlencoded)
- [x] HTTP Verbs support
- [x] query param parsing
- [x] next() (very fucking difficult)
- [ ] cookie parsing (sort of works)
- [x] `use` middleware
- [x] Static files
- [ ] Compression (gzip + ???)

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