# hapi-bookshelf-rest

> REST Full API for hapi framework based on bookshelf models

Latest version **1.17.0** (published 2018-03-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install hapi-bookshelf-rest
pnpm add hapi-bookshelf-rest
yarn add hapi-bookshelf-rest
bun add hapi-bookshelf-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.17.0 |
| Published | 2018-03-03 |
| First published | 2017-08-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 132.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | doniyor2109 |
| Keywords | hapi, bookshelf, rest |

## Links

- npm: https://www.npmjs.com/package/hapi-bookshelf-rest
- Repository: https://github.com/doniyor2109/hapi-bookshelf-rest
- Homepage: https://github.com/doniyor2109/hapi-bookshelf-rest#readme
- Issues: https://github.com/doniyor2109/hapi-bookshelf-rest/issues
- npm.io page: https://npm.io/package/hapi-bookshelf-rest

## Dependencies (3)

- [joi](https://npm.io/package/joi.md) ^10.6.0
- [boom](https://npm.io/package/boom.md) ^5.2.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.0

## Recent versions

- 1.17.0 (latest) — 2018-03-03
- 1.16.8 (beta) — 2017-12-01
- 1.16.12 — 2017-12-08
- 1.16.11 — 2017-12-03
- 1.16.10 — 2017-12-03
- 1.16.9 — 2017-12-01
- 1.16.7 — 2017-09-18
- 1.16.6 — 2017-09-18
- 1.16.5 — 2017-08-24
- 1.16.4 — 2017-08-23
- 1.16.3 — 2017-08-23
- 1.16.2 — 2017-08-22
- 1.16.1 — 2017-08-18
- 1.16.0 — 2017-08-18
- 1.15.3 — 2017-08-17
- … 30 more at https://npm.io/package/hapi-bookshelf-rest/versions

## README

# hapi-bookshelf-rest
REST Full API for hapi framework based on bookshelf models


## Getting Started


### Installation

#### npm
```javascript
npm install hapi-bookshelf-rest
```

#### yarn
```
yarn add hapi-bookshelf-rest
```

#### git
```
git clone https://github.com/doniyor2109/hapi-bookshelf-rest
```
## Introduction
This plugin provides easy way to develop REST API server with few configuration. There is already built in standarts that you can use. If there is standarts that plugin does not have please [issue](https://github.com/doniyor2109/hapi-bookshelf-rest/issues) this standart.

## Configure your REST
```javascript
const rest = require('hapi-bookshelf-rest');

rest(server, {
   path: '/user',
   model: BookshelfModel,
   bookshelf: bookshelf,
}).generateRoutes();
```

This is the basic configuration for REST API. These lines of codes provide full featured REST API for `user` resource. You can configure your routes with options and routeConfig.

### Customize your rest route

```javascript
const rest = require('hapi-bookshelf-rest');

rest(server, {
   path: '/user',
   model: BookshelfModel,
   bookshelf: bookshelf,
}).readAll({
     queryFilter: function(request) {
         return {
            id: request.auth.credentials.id,
         }
     }
}).generateRoutes();
```

This route is configured that whenever user requests `GET /user` path (readAll), user resource will be fetched with condition that `id` should be equal to `request.auth.credentials.id`.
This configuration is belongs to only `GET /user` path (readAll).


## API

`rest = require('hapi-bookshelf-rest')`

* `rest(server, [options], [routeConfig])` : `Rest`:`object`
   * `server`:`object` - hapi server instance
   * `[options]`:`object` - global options from [configuration](/#configuration)
   * `[routeConfig]`:`object` - global route configuration from [configuration](/#configuration)
* `Rest`:`object` -  sets configuration and options for routes
   * `readOne([options], [routeConfig])` - reads one resource - `GET /path/{id}` 
      * `[options]`:`object` - local options from [configuration](/#configuration)
      * `[routeConfig]`:`object` - local route configuration from [configuration](/#configuration)
   * `readAll([options], [routeConfig])` -  reads all resource - `GET /path` 
      * `[options]`:`object` - local options from [configuration](/#configuration)
      * `[routeConfig]`: `object` - local route configuration from [configuration](/#configuration)
   * `create([options], [routeConfig])` - creates new resource - `POST /path` 
      * `[options]`:`object` - local options from [configuration](/#configuration)
      * `[routeConfig]`:`object` - local route configuration from [configuration](/#configuration)
   * `batch([options], [routeConfig])` -  creates multuple resources - `POST /path/batch` 
      * `[options]`:`object` - local options from [configuration](/#configuration)
      * `[routeConfig]`:`object` - local route configuration from [configuration](/#configuration)
   * `update([options], [routeConfig])` - updates resource - `PUT /path/{id}` 
      * `[options]`:`object` - local options from [configuration](/#configuration)
      * `[routeConfig]`: `object` - local route configuration from [configuration](/#configuration)
   * `delete([options], [routeConfig])` - deletes resource - `DELETE /path/{id}` 
      * `[options]`:`object` - local options from [configuration](/#configuration)
      * `[routeConfig]`:`object` - local route configuration from [configuration](/#configuration)
   * `generateRoutes()`:`void` - generates routes

### Configuration

* `[options]`:`object` - global options for every route
   * `path`:`string` - base path for REST API.
   * `model`:`bookshelfModel object` - resource model
   * `bookshelf`:`BookshelfInstance object` - bookshelf instance
   * `[queryFilter]`:`function` - modify query
   * `[payloadFilter]`:`function` - modify payload
   * `[deny]`:`function` - if returns true then user is not allowed to this route
* `[routeConfig]`:`object` - global route config for every route - same as Hapi route options
   * `handler`:`function` - route handler function
   * ... .etc

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