# jap-express

> Jap plugin for express

Latest version **1.2.0** (published 2020-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install jap-express
pnpm add jap-express
yarn add jap-express
bun add jap-express
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2020-01-20 |
| First published | 2019-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Mikhail Lysikov |
| Maintainers | deight |
| Keywords | JSON, REST, API, express, plugin |

## Links

- npm: https://www.npmjs.com/package/jap-express
- Repository: https://github.com/d8corp/jap-express
- Homepage: https://github.com/d8corp/jap-express#readme
- Issues: https://github.com/d8corp/jap-express/issues
- npm.io page: https://npm.io/package/jap-express

## Dependencies (3)

- [jap](https://npm.io/package/jap.md) ^1.2.0
- [express](https://npm.io/package/express.md) ^4.17.1
- [@types/express](https://npm.io/package/@types/express.md) ^4.17.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.2.0 (latest) — 2020-01-20
- 1.1.0 — 2020-01-19
- 1.0.4 — 2019-10-27
- 1.0.3 — 2019-10-26
- 1.0.2 — 2019-10-26
- 1.0.1 — 2019-10-26
- 1.0.0 — 2019-10-21

## README

# jap-express
[npm](https://www.npmjs.com/package/jap-express) | [github](https://github.com/d8corp/jap-express)  
This is a plugin for [express](https://expressjs.com/) to [jap](https://www.npmjs.com/package/jap) your app. 
### Install with npm
```bash
npm i jap-express
```
### Install with yarn
```bash
yarn add jap-express
```
### Arguments
japExpress(  
`handler: object | Jap`,  
`resolve?: (data: json) => json`,  
`reject?: (data: json, error: Error, handler) => json`,  
`start?: (req, res) => void`,  
`end?: (req, res) => void`,  
`context?: any`  
)  
### Simple example 
- Add file `index.js`
```javascript
const express = require('express')
const jap = require('jap-express')

const app = express()

app.get('/', (req, res) => res.send(''))
app.post('/', jap({secret: p => p === 420 ? 42 : null}))
app.listen(3000)
```
- Run the app
```bash
node index.js
```
- Open browser with `http://localhost:3000/` and run the next code in console
```javascript
fetch('/', {
  method: 'post',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: '{"secret": 420}'
}).then(data => data.json()).then(console.log)
```
### Jap
You may use `Jap`, this is a good way to have separately space for each request  
- Add `classic.js`
```javascript
const express = require('express')
const jap, { Jap } = require('jap-express')

const app = express()

class App extends Jap {
  userAgent () {
    return this.$req.headers['user-agent']
  }
}

app.get('/', (req, res) => res.send(''))
app.post('/', jap(App))
app.listen(3001)

```
- Run the app
```bash
node classic.js
```
- Open browser with `http://localhost:3001/` and run the next code in console
```javascript
fetch('/', {
  method: 'post',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: '{"userAgent": null}'
}).then(data => data.json()).then(console.log)
```
### Real example
You may look at real example with [jap](https://www.npmjs.com/package/jap):
```bash
git clone https://github.com/d8corp/jap.git
cd jap
npm i
npm start
```

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