# @clocklimited/cf-crud-service-api-builder

> Build an HTTP API for a crud-service

Latest version **2.1.2** (published 2024-01-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install @clocklimited/cf-crud-service-api-builder
pnpm add @clocklimited/cf-crud-service-api-builder
yarn add @clocklimited/cf-crud-service-api-builder
bun add @clocklimited/cf-crud-service-api-builder
```

## 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 | 2.1.2 |
| Published | 2024-01-08 |
| First published | 2022-06-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14.0.0 |
| Dependencies | 2 |
| Unpacked size | 15.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Clock Limited |
| Maintainers | mrstebo, scott-clock, clock-release-bot, steepnicki, asheboy |

## Links

- npm: https://www.npmjs.com/package/@clocklimited/cf-crud-service-api-builder
- Repository: https://github.com/clocklimited/cf-crud-service-api-builder
- Issues: https://github.com/clocklimited/cf-crud-service-api-builder/issues
- npm.io page: https://npm.io/package/@clocklimited/cf-crud-service-api-builder

## Dependencies (2)

- [async](https://npm.io/package/async.md) ^2.6.4
- [piton-pipe](https://npm.io/package/piton-pipe.md) 0.0.4

## Recent versions

- 2.1.2 (latest) — 2024-01-08
- 2.1.1 — 2024-01-08
- 0.7.0 — 2023-04-13
- 1.2.0 — 2023-04-13
- 2.1.0 — 2023-03-16
- 2.0.0 — 2022-06-14
- 1.1.0 — 2022-06-14

## README

# @clocklimited/cf-crud-service-api-builder

[![CircleCI](https://circleci.com/gh/clocklimited/cf-crud-service-api-builder/tree/master.svg?style=shield)](https://circleci.com/gh/clocklimited/cf-crud-service-api-builder/tree/master)

Build an HTTP API for a [@clocklimited/crud-service](https://github.com/clocklimited/crud-service).

## Installation

```
npm install --save @clocklimited/cf-crud-service-api-builder
npm install --save @clocklimited/schemata
```

## Usage

```js
const crudServiceApiBuilder = require('cf-crud-service-api-builder')
const router = require('express')()
const logger = require('bunyan').createLogger()
const service = require('./service')
const middleware = require('./auth-check-middleware')

crudServiceApiBuilder(service, '/widgets', router, logger, middleware)
```

### Hooks

When using the api builder, you can hook into certain actions to manipulate the request data before it is sent to the database or the response data before it is sent to the requester.

```js
const api = crudServiceApiBuilder(
  service,
  '/article',
  router,
  logger,
  middleware
)

api.hook('create:request', function (data, cb) {
  // do whatever you like with the data
  cb(null, data)
})
```

Supported hooks are:

- `create:request`
- `create:response`
- `read:response`
- `update:request`
- `update:response`
- `partialUpdate:request`
- `partialUpdate:response`

### Events

When using the api builder, you can listen for certain events so that you can add hooks to perform your own actions after a request has been succesful. e.g

```js
const api = crudServiceApiBuilder(
  service,
  '/article',
  router,
  logger,
  middleware
)

api.on('create', function (req, newArticle) {
  // do whatever you like with the req and article object
})
```

Supported events are:

- `create`
- `update`
- `partialUpdate`
- `delete`

## Credits

Built by developers at [Clock](http://clock.co.uk).

## Licence

Licensed under the [ISC](http://opensource.org/licenses/isc)

---
_Source: https://npm.io/package/@clocklimited/cf-crud-service-api-builder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
