1.0.6 • Published 3 years ago

api-url-tree-generator v1.0.6

Weekly downloads
12
License
MIT
Repository
github
Last release
3 years ago

Api generator for frontend

Generates an object with API urls as values

Installation

npm install --save-dev api-url-tree-generator

or

yarn add --dev api-url-tree-generator

Usage

const baseUrl = "https://something.com"
const apiRaw = {
  simpleRoute: 'simple-route',
  'other-route': 'other-route',
  'node': {
    nestedRoute: 'nested-route'
  }
}

const options = {
  // ...
}

const api = generateApi(baseUrl, apiRaw, options)
/*
  api => {
      simpleRoute: 'https://something.com/simple-route',
      'other-route': 'https://something.com/other-route',
      'node': {
        nestedRoute: 'https://something.com/node/nested-route'
      }
  }

  Also, api.node translates to https://something.com/node
*/

// request to 'https://something.com/simple-route'
const response = await fetch(api.simpleRoute);

// request to 'https://something.com/node'
const response = await fetch(api.node);

// request to 'https://something.com/node/nested-route'
const response = await fetch(api.node.nestedRoute);

Options

OptionTypeDescription
withTailingSlashbooleanAdds tailing slash to url

License

MIT

1.0.6

3 years ago

1.0.2

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago