Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apish-fork

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apish-fork

Mock APIs and Services from API Blueprint or Swagger

  • 1.2.14
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coveralls Status David dependencies npm downloads

apish - Mock APIs and Services

Describe any API or Service you need mocked. Supports API Blueprint and Swagger API Description formats.

Use cases

3rd party APIs
  • Your app is calling GitHub API, weather API, Trello API, …
  • Describe endpoints in API Description format like API Blueprint (or ask API provider for API Description)
  • Add it as a test fixture and let apish create mock for you:
before(() => {
  return apish(fs.readFileSync('github-api.apib', 'utf8'));
});

// Run your tests with mocked requests against GitHub API
(Micro)services
  • Have all your services publish API Description onto (private) npm. Use semver to version it and tools like Dredd to test its implementation
  • When you depend on another service, just require its package with API Description and run tests against its mocks, that are always in sync with implementation
  • You can always compare version you've tested against to what is currently running in your environment
import myOtherService from 'myOtherService';

before(() => {
  return myOtherService = apish(myOtherService);
});

// Run your tests…

Installation

$ npm i apish -D

Usage

import apish from 'apish';

// In your test runner
let mockResult = {};
before(() => {
  const apib = fs.readFileSync('github-api.apib', 'utf8');
  return mockResult = apish(apib); // apish returns a Promise
});

// Cleanup
after(() => {
  // .value() is Promise-related helper in this case
  mockResult.value().restore();
});

Arguments

const mockedApi = apish(apiDescription, options);
  • apiDescription (string) - API Blueprint or Swagger API Description
  • options (OPTIONAL, object)
    • host (string) - overwrite specified host (base URL) that should be used

returns Promise

Resolved promise returns object with methods:

  • restore() - clears all mocks for this host

License

MIT

Keywords

FAQs

Package last updated on 18 Jul 2017

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