# swagger-fluent

> A fluent client for OpenAPI and Swagger

Latest version **5.0.3** (published 2020-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install swagger-fluent
pnpm add swagger-fluent
yarn add swagger-fluent
bun add swagger-fluent
```

## 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 | 5.0.3 |
| Published | 2020-04-30 |
| First published | 2018-12-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 25 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Silas Boyd-Wickizer |
| Maintainers | sbw |
| Keywords | swagger, openapi, client |

## Links

- npm: https://www.npmjs.com/package/swagger-fluent
- Repository: https://github.com/silasbw/swagger-fluent
- Homepage: https://github.com/silasbw/swagger-fluent#readme
- Issues: https://github.com/silasbw/swagger-fluent/issues
- npm.io page: https://npm.io/package/swagger-fluent

## Dependencies (3)

- [request](https://npm.io/package/request.md) ^2.88.0
- [deepmerge](https://npm.io/package/deepmerge.md) ^4.2.2
- [is-plain-object](https://npm.io/package/is-plain-object.md) ^3.0.0

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 5.0.3 (latest) — 2020-04-30
- 5.0.2 — 2020-04-29
- 5.0.1 — 2020-04-09
- 5.0.0 — 2020-04-08
- 4.0.0 — 2019-11-02
- 3.2.1 — 2019-05-25
- 3.2.0 — 2019-05-24
- 3.1.4 — 2019-05-20
- 3.1.3 — 2019-05-07
- 3.1.2 — 2019-03-05
- 3.1.1 — 2018-12-29
- 3.1.0 — 2018-12-29

## README

# swagger-fluent

[![Build Status][build]](https://travis-ci.org/silasbw/swagger-fluent) [![Greenkeeper badge][greenkeeper]](https://greenkeeper.io/)

[greenkeeper]: https://badges.greenkeeper.io/silasbw/swagger-fluent.svg
[build]: https://travis-ci.org/silasbw/swagger-fluent.svg?branch=master

A fluent OpenAPI and Swagger client for JavaScript and Node.js.

fluent-client represents [Path Item
Object](https://swagger.io/specification/#pathItemObject) with chains
of objects:

```
/api/v1/namespaces -> api.v1.namespaces
```

associates operations on a Path Item Object with functions:

```
/api/v1/namespaces -> api.v1.namespaces.get()
```

and represents [Path
Templating](https://swagger.io/specification/#pathTemplating) with
function calls:

```
/api/v1/namespaces/{namespace}/pods -> api.v1.namespaces(namespace).pods
```

Configurable "backends" handle executing API calls by, for example,
using [`fetch`](#fetchbackendoptions) or [Swagger
Client](#swaggerclientbackendoptions). A backend can also perform
error checking.  The Swagger Client backend, for example, will perform
the usual parameter and resolution checking that
[swagger-js](https://github.com/swagger-api/swagger-js) performs and
will throw those errors to the caller.

## Using

```js
const spec = require('./swagger.json')
const url = 'https://petstore.swagger.io/v2/'
const FetchBackend = require('swagger-fluent/backends/fetch')
const backend = new FetchBackend({ fetch, url })

const { Client } = require('swagger-fluent')
const client = new Client({ spec, backend })

const response = await client.pet.findByStatus.get({ parameters: { status: 'available' } })
```

## API

### `Client(options)`

Create a fluent client for an OpenAPI or Swagger specification.

* `options.spec` - OpenAPI or Swagger specification.
* `options.backend` - Object with an `.http` method that executes HTTP
r equests.
* `options.getNames(name, ancestors)` - a function to translate each
path name to an alternate name or array of names. You could, for
example, alias the resource "namespaces" to "namespace" and "ns".

### `FetchBackend(options)`

Create a [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)-based
backend.

* `options.fetch` - `fetch` function (*e.g.*,
[`node-fetch`](https://www.npmjs.com/package/node-fetch) or
[`whatwg-fetch`](https://www.npmjs.com/package/whatwg-fetch)).
* `options.url` - Base URL for HTTP API.

```js
const FetchBackend = require('swagger-fluent/backends/fetch')
```

### `RequestBackend(options)`

```js
const RequestBackend = require('swagger-fluent/backends/request')
```

### `SwaggerClientBackend(options)`

Create a [swagger-js](https://github.com/swagger-api/swagger-js)-based
backend.

```js
const SwaggetClientBackend = require('swagger-fluent/backends/swagger-client')
```

### Custom backend

The backend must implement an `.http` method. swagger-fluent passes
the following options to the `.http` method, and returns the result
directly to the API caller.

* `options.body` - JSONifable object.
* `options.method` - HTTP method.
* `options.pathItemObject` - Swagger/OpenAPI Path Item Object.
* `options.parameters` - named query parameters.
* `options.qs` - named query parameters (legacy).
* `options.pathname` - URL pathname.
* `options.stream` - true if called by a "stream method".

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