# nanium-channel-rest

> a nanium request channel that creates REST-style endpoints for the nanium services

Latest version **1.0.6** (published 2022-04-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install nanium-channel-rest
pnpm add nanium-channel-rest
yarn add nanium-channel-rest
bun add nanium-channel-rest
```

## 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.6 |
| Published | 2022-04-14 |
| First published | 2021-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tobias Wenzel |
| Maintainers | twnzl |
| Keywords | nanium, channel, rest |

## Links

- npm: https://www.npmjs.com/package/nanium-channel-rest
- npm.io page: https://npm.io/package/nanium-channel-rest

## Dependencies (1)

- [nanium](https://npm.io/package/nanium.md) ^1.14.1

## Recent versions

- 1.0.6 (latest) — 2022-04-14
- 1.0.5 — 2022-04-14
- 1.0.4 — 2022-03-21
- 1.0.3 — 2022-02-10
- 1.0.2 — 2022-01-24
- 1.0.1 — 2022-01-07
- 1.0.0 — 2021-12-15

## README

# nanium-channel-rest

A nanium request channel that creates REST-style endpoints for the nanium services

## Install
```bash
npm install nanium-channel-rest
```

## Usage
```ts
import { Nanium } from 'nanium/core';
import { NaniumRestChannel } from 'nanium-channel-rest';

const httpServer = http.createServer((_req, _res) => {});
httpServer.listen(3000);

await Nanium.addManager(new NaniumNodejsProvider({
    servicePath: 'services',
    requestChannels: [
        new NaniumRestChannel({
            apiBasePath: '/api',
            server: httpServer
        })
    ]
}));
```

This creates an HTTP endpoint for each service based on the service name.

## HTTP methods
Which HTTP method is used depends on the name of the contract.ts file;

GET:
- get.contract.ts
- query.contract.ts

PUT:
- update.contract.ts
- change.contract.ts
- store.contract.ts
- put.contract.ts

DELETE:
- remove.contract.ts
- delete.contract.ts

POST:
- create.contract.ts
- add.contract.ts
- post.contract.ts
- everything else

## HTTP request deserialization
Properties of __HTTP-header__ will be available in request.head.
Properties of __HTTP-body__ and __querystring__ will be available in request.body.
The request will have two additional properties:
- __request['$$rawBody']__ = raw body as buffer;
- __request['$$requestSource']__ = remoteAddress or 'x-forwarded-for' header

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