@aida/consumer-faked-http

0.0.7 • Public • Published

Consumer - Faked HTTP

Introduction

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.

Example

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.

API

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.

Notes

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.

Readme

Keywords

Package Sidebar

Install

npm i @aida/consumer-faked-http

Weekly Downloads

3

Version

0.0.7

License

MIT

Unpacked Size

10.4 kB

Total Files

7

Last publish

Collaborators

  • sradevski