# fortune-json-api

> JSON API serializer for Fortune.

Latest version **2.3.1** (published 2024-02-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install fortune-json-api
pnpm add fortune-json-api
yarn add fortune-json-api
bun add fortune-json-api
```

## 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.3.1 |
| Published | 2024-02-12 |
| First published | 2015-08-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 48.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 61 |
| Maintainers | daliwali, ctcpip |
| Keywords | json, api, fortune, http, hypermedia, rest, serializer |

## Links

- npm: https://www.npmjs.com/package/fortune-json-api
- Repository: https://github.com/fortunejs/fortune-json-api
- Homepage: https://github.com/fortunejs/fortune-json-api#readme
- Issues: https://github.com/fortunejs/fortune-json-api/issues
- npm.io page: https://npm.io/package/fortune-json-api

## Dependencies (3)

- [deep-equal](https://npm.io/package/deep-equal.md) ^2.0.1
- [inflection](https://npm.io/package/inflection.md) ^1.13.4
- [uri-templates](https://npm.io/package/uri-templates.md) ^0.2.0

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

- 2.3.1 (latest) — 2024-02-12
- 2.3.0 — 2020-03-10
- 2.2.3 — 2020-01-21
- 2.2.2 — 2020-01-13
- 2.2.1 — 2020-01-07
- 2.2.0 — 2019-02-14
- 2.1.5 — 2018-05-30
- 2.1.4 — 2018-05-29
- 2.1.3 — 2018-03-16
- 2.1.2 — 2017-05-11
- 2.1.1 — 2017-02-04
- 2.1.0 — 2016-11-22
- 2.0.14 — 2016-09-28
- 2.0.13 — 2016-09-14
- 2.0.12 — 2016-09-05
- … 31 more at https://npm.io/package/fortune-json-api/versions

## README

# Fortune JSON API Serializer

[![Build Status](https://img.shields.io/travis/fortunejs/fortune-json-api/master.svg?style=flat-square)](https://travis-ci.org/fortunejs/fortune-json-api)
[![npm Version](https://img.shields.io/npm/v/fortune-json-api.svg?style=flat-square)](https://www.npmjs.com/package/fortune-json-api)
[![License](https://img.shields.io/npm/l/fortune-json-api.svg?style=flat-square)](https://raw.githubusercontent.com/fortunejs/fortune-json-api/master/LICENSE)

This is a [JSON API](http://jsonapi.org) serializer for [Fortune.js](http://fortune.js.org/), which implements all of the features in the [base specification](http://jsonapi.org/format/), and follows the [recommendations](http://jsonapi.org/recommendations/) as much as possible.

```sh
$ npm install fortune fortune-http fortune-json-api
```


## Usage

```js
const http = require('http')
const fortune = require('fortune')
const fortuneHTTP = require('fortune-http')
const jsonApiSerializer = require('fortune-json-api')

// `instance` is an instance of Fortune.js.
const listener = fortuneHTTP(instance, {
  serializers: [
    // The `options` object here is optional.
    [ jsonApiSerializer, options ]
  ]
})
// The listener function may be used as a standalone server, or
// may be composed as part of a framework.
const server = http.createServer((request, response) =>
  listener(request, response)
  .catch(error => { /* error logging */ }))

server.listen(8080)
```

The `options` object is as follows:

- `prefix`: hyperlink prefix. If this prefix starts with `/`, then it will rewrite paths relative to the prefix. For example, a prefix valued `/api` will handle requests at that route like `/api/users/1`. Default: `""` (empty string).
- `inflectType`: pluralize and dasherize the record type name in the URI. Can be Boolean to enable/disable all inflections or an object specifying each type in specific with unreferenced types set to default, ex: `{ faculty: false }`. Default: `true`.
- `inflectKeys`: camelize the field names per record. Default: `true`.
- `maxLimit`: maximum number of records to show per page. Default: `1000`.
- `includeLimit`: maximum depth of fields per include. Default: `3`.
- `bufferEncoding`: which encoding type to use for input buffer fields. Default: `base64`.
- `jsonSpaces`: how many spaces to use for pretty printing JSON. Default: `2`.
- `jsonapi`: top-level object mainly used for describing version. Default: `{ version: '1.0' }`.
- `castNumericIds`: whether to cast numeric id strings to numbers. Default: `true`.

Internal options:

- `uriTemplate`: URI template string.
- `allowLevel`: HTTP methods to allow ordered by appearance in URI template.


## License

This software is licensed under the [MIT license](https://raw.githubusercontent.com/fortunejs/fortune-json-api/master/LICENSE).

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