# @zerowastemap/api-factory-generator

> - Uses fetch - Uses ajv for schema validation - Sane defaults - Sends token if provided - Each route can have specific options

Latest version **0.3.0** (published 2019-01-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zerowastemap/api-factory-generator
pnpm add @zerowastemap/api-factory-generator
yarn add @zerowastemap/api-factory-generator
bun add @zerowastemap/api-factory-generator
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2019-01-15 |
| First published | 2019-01-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Augustin Godiscal |
| Maintainers | auggod |

## Links

- npm: https://www.npmjs.com/package/@zerowastemap/api-factory-generator
- npm.io page: https://npm.io/package/@zerowastemap/api-factory-generator

## Dependencies (3)

- [ajv](https://npm.io/package/ajv.md) ^6.6.2
- [isobject](https://npm.io/package/isobject.md) ^3.0.1
- [query-string](https://npm.io/package/query-string.md) ^6.2.0

## Recent versions

- 0.3.0 (latest) — 2019-01-15
- 0.2.2 — 2019-01-14
- 0.2.1 — 2019-01-14
- 0.2.0 — 2019-01-12
- 0.1.0 — 2019-01-12
- 0.0.1 — 2019-01-11

## README

# [WIP] API factory generator

- Uses fetch
- Uses ajv for schema validation
- Sane defaults
- Sends token if provided
- Each route can have specific options

# Usage

```javascript

const generator = require('@zerowastemap/api-factory-generator')

// set default options for each requests
const options = {
  mode: 'cors',
  domain: 'zerowastemap.localhost',
  scheme: 'https://',
  prefix: '/api',
  version: 1,
  token: 'some bearer token'
}

// configure your routes
// you can nest routes
const routes = {
  auth: {
    login: {
      path: '/auth/login',
      options: {
        method: 'POST'
      },
      schema: {
        type: 'object',
        required: ['email'],
        properties: {
          email: {
            type: 'string'
          }
        }
      }
    }
  },
  upload: {
    path: '/locate',
    options: {
      method: 'POST',
      auth: true, // will enable credentials
      multipart: true
    }
  }
  locate: {
    path: '/locate',
    schema: {
      type: 'object',
      required: ['longitude', 'latitude'],
      properties: {
        longitude: Longitude,
        latitude: Latitude
      }
    }
  }
}

const api = generator(routes, options) 

// api.auth.login('salut@zerowastemap.app') works too if we have a schema
api.auth.login({ email: 'salut@zerowastemap.app' }).then(response => {
  ...
})

```

# See also

[JavaScript Factory Functions vs Constructor Functions vs Classes](https://medium.com/javascript-scene/javascript-factory-functions-vs-constructor-functions-vs-classes-2f22ceddf33e)

# Testing

Tests won't work on your machine because it test against api which is not released yet

# LICENSE

MIT

# Author(s)

- Augustin Godiscal <salut@zerowastemap.app>

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