1.0.17 • Published 3 years ago

@cloudflare/util-mock-api v1.0.17

Weekly downloads
58
License
BSD-3-Clause
Repository
-
Last release
3 years ago

util-mock-api

Express style, in-memory API scaffolding for mocking backends that don't exist yet.

Prototype faster, now, today.

Installation

$ npm install @cloudflare/util-mock-api

Usage

In your feature, make a mockApi.ts and implement your own api responses and store.

import mockApi from '@cloudflare/util-mock-api'

// persist your store in localStorage
const _storedWorkers = window.localStorage.getItem('storedWorkers')


// fetchGetWorkerDetails({ routeParams, queryParams }) => ...
const fetchGetWorkerDetails = ({ routeParams }) => {
  const found = _storedWorkers.find(
    worker => worker.script_id === routeParams.workerId,
  )

  return {
    body: {
      result: found,
    }
  }
}

export default mockApi.server({
  endpoints: [
    {
      route: '/api/v3/workers/scripts/:workerId/details',
      response: fetchGetWorkerDetails,
    }
  ]
})

When mockApi.server() appears in your code, Mock API controls appear in the top corner of your UI where you can toggle the mock server on and off as well as clear the current mock data. Clearing mock data will generate fresh mocks.

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago