Mocks XHR and Fetch API and responds with faked data

Usage no npm install needed!

<script type="module">
  import aidaConsumerFakedHttp from 'https://cdn.skypack.dev/@aida/consumer-faked-http';


Consumer - Faked HTTP


The Faked HTTP consumer consumes the results generated from @aida/injector-faked-routes. Its purpose is to take the file that contains all endpoints with fake data generated by the injector, and to override the supported HTTP request mechanisms so requests return mocked data instead of making a request over the wire. Only XMLHttpRequest and fetch are currently supported and automatically mocked.

Use Cases

The main use case for this consumer is to mock APIs your JS-based application, so development can be done independently from the backend. It can be used with any framework and platform that supports either XMLHttpRequest or fetch APIs.


import mockHttp from '@aida/consumer-faked-http';
import fakedEndpoints from './fakedEndpoints'; //This is the file generated by @aida/injector-faked-routes

const baseUri = 'http://localhost:4000';
const options = { timing: 1500 };
mockHttp(fakedEndpoints, baseUri, options); //This will override the supported HTTP request mechanisms and start serving mocked data.


mockHttp(fakedEndpoints, baseUri[, options]) (default export)

  • fakedEndpoints - output generated by @aida/injector-faked-http
  • baseUri - The base url to which your requests are directed at, such as http://localhost:3000 or https://example.com/api**
  • options - An object of options
    • timing - Delay before response in ms. Defaults to 0.


Some points to consider when using the consumer are:

  • The response comes from the status 200 if defined, otherwise it comes from the first response defined in the endpoints file.
  • If a route is not defined in the endpoints file, it is passed through. All other routes are mocked.