Skip to content

All About APIs - Servers and tools.

Frameworks

PHP

Python

Node.js API Frameworks

API Tools

Docs

API Documentation Tools

API Mock Tools

Mock Service

  • Mockbin - test, mock and track http requests & responses

How To - Mock API Server

Other

Creating a mock api server - node.js

  • Using json-server
  • Setup
    1. Create directory - test_server
    2. touch server.js - server startup file
    3. npm init - create config file. Set server.js as the start script.
    4. Create server.js file.
    5. npm install faker json-server --save-dev
    //server.js
    const jsonServer = require('json-server')
    const customers = require('./customers')
    const server = jsonServer.create()
    const router = jsonServer.router(customers())
    const middlewares = jsonServer.defaults()

    server.use(middlewares)
    server.use(router)
    server.listen(3000, () => {
      console.log('JSON Server is running')
    })

    //customer.js
    var faker = require('faker')
    function generateCustomers () {
        var customers = []
        for (var id = 0; id < 50; id++) {

        var firstName = faker.name.firstName();
        var lastName = faker.name.lastName();
        var phoneNumber = faker.phone.phoneNumberFormat();

        customers.push({
            "id": id,
            "first_name": firstName,
            "last_name": lastName,
            "phone": phoneNumber
        })
    }
    return { "customers": customers}
    }
    module.exports = generateCustomers

REST Test Endpoints