šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

@cloudflare/util-mock-api

Package Overview
Dependencies
Maintainers
19
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloudflare/util-mock-api

In-memory API scaffolding for mocking backends that don't exist yet.

1.0.17
latest
npm
Version published
Maintainers
19
Created
Source

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.

FAQs

Package last updated on 28 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts