Skip to content

jgiovaresco/stub-api-server

Repository files navigation

ci codecov release

stub-api-server

This lib allows you to configure an HTTP server responding dynamic fake JSON.

The common usecase is stubbing a REST API for Integration Tests.

Introduction

stub-api-server allow you to define an endpoint based on a simple object

// routes/route.ts
import { RouteConfig } from 'stub-api-server';

const route: RouteConfig = {
  method: 'GET',
  path: '/hello',
  template: { message: 'Hello World' },
};

export default route;
// index.ts
import path from 'path';
import { StubApiServer } from 'stub-api-server';

const server = new StubApiServer();
server.useRoutesFromDir(path.resolve('./routes'));
server.start();
➜ ts-node index.ts
Starting server on http://localhost:8000