New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aida/consumer-faked-http

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aida/consumer-faked-http

Mocks XHR and Fetch API and responds with faked data

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-25%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 17 Jun 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc