node package manager

@springworks/static-api-server

A static version of an API, responding with fixtures

Static API Server

Greenkeeper badge

Useful to mimic behavior of an actual API server, but with static fixture responses instead.

Usage

Install dependency:

npm install -D @springworks/static-api-server

Send requests to API and get matching fixtures back:

 
import static_api_server from '@springworks/static-api-server';
import { createFixtureLoader } from 'fixture-loader';
 
const fixture_loader = createFixtureLoader('./path-to-fixtures');
static_api_server.createServer({
    swagger_spec: swagger_spec,
    fixture_loader: fixture_loader,
    host: 'localhost',
    port: 3001,
  })
  .then(created_server => {
    created_server.start().then(() => {
      // Send requests to server, which will respond with successful status code and fixture 
      // created_server.stop() when done 
    });
  });
 

API

createServer({ swagger_spec, fixture_loader, host, port })

Creates and configures a Hapi server. Routes defined in swagger_spec will be matched with fixtures from fixture_loader.

Returns a Hapi server instance.

Notes

This module uses the semantic-release automated package publishing. Which means that the commit messages are required to look in a certain way.

To ensure this pattern is enforced, we use pre-git which installs a commit-msg hook. Please read and understand what the types mean and use them properly when committing and contributing.

The commit-msg hook needs to know about your installed node which means that if you use third party application when committing, like Tower, that application needs to know your PATH environment. There are probably a lot of ways to solve this, but one that works is to open the application from the terminal: open /Applications/Tower.app.

Contributing

  1. Write a new test with new fixtures or extend the existing ones
  2. Make a PR
  3. 🙏 👏