ESME is a go library that allows you to mock a RESTful service by defining the configuration in json format

What is Embeddable Service Mocking Engine (ESME)?

ESME is a go library that allows you to mock a RESTful service by defining the configuration in json format. This service can then simply be consumed by any client to get the expected response.

Where can it be used?

  • while developing frontend
  • while consuming external APIs
  • to set up an API with static content

Usage

Here is a sample route-config.json file that can be processed by ESME

{
  "routes": [
    {
      "url": "/users/1",
      "method": "GET",
      "status_code": 200,
      "response": [
        {
          "firstName": "jane",
          "lastName": "doe",
          "id": 1
        },
        {
          "firstName": "john",
          "lastName": "doe",
          "id": 2
        }
      ],
      "auth": {
        "basic": {
          "username": "username",
          "password": "password"
        }
      }
    },
    {
      "url": "/user",
      "method": "POST",
      "status_code": 201,
      "body": {
        "firstName": "foo",
        "lastName": "bar"
      },
      "response": {
        "firstName": "foo",
        "lastName": "bar"
      },
      "auth": {
        "bearer_token": {
          "token": "token"
        }
      }
    },
    {
      "url": "/user/1",
      "method": "DELETE",
      "status_code": 200,
      "response": "success",
      "auth": {
        "custom": {
          "my_header": "value"
        }
      }
    }
  ]
}

Start a mock server using above route-config.json file

package main

import (
	"github.com/stkr89/esme"
)

func main() {
	esme.Serve("8080", "./route-config.json")
}

You can also provide multiple route configs as arguments to Serve method.

Let's break down this file to understand what each component means.

Routes

routes contains the list of routes which need to be mocked. ESME supports adding routes to multiple files which can represent different services running simultaneously.

URL

url defines the route that need to be mocked.

Method

method defines the http method associated with an url.

Status Code

status_code defines the http status code that needs to be returned from the endpoint.

Response

Array

{
  "response": [
    {
      "firstName": "jane",
      "lastName": "doe",
      "id": 1
    },
    {
      "firstName": "john",
      "lastName": "doe",
      "id": 2
    }
  ]
}

Object

{
  "response": {
    "firstName": "jane",
    "lastName": "doe",
    "id": 1
  }
}

String

{
  "response": "success"
}

response defines an array, object or string that the endpoint returns on success.

Auth

auth defines the authentication scheme required for an endpoint. Each url can have its own authentication scheme. ESME supports following authentication schemes:

Basic

{
  "auth": {
    "basic": {
      "username": "username",
      "password": "password"
    }
  }
}

basic authentication checks for a header field in the form of Authorization: Basic , where is the Base64 encoding of username and password joined by a single colon :.

Bearer Token

{
  "auth": {
    "bearer_token": {
      "token": "token"
    }
  }
}

bearer_token authentication checks for a header field in the form of Authorization: Bearer .

Custom

{
  "auth": {
    "custom": {
      "my_header_1": "value1",
      "my_header_2": "value2"
    }
  }
}

custom authentication checks for headers my_header_1 and my_header_2 with values value1 and value2 respectively.

Owner
Similar Resources

mockery - A mock code autogenerator for Golang

mockery - A mock code autogenerator for Golang

mockery - A mock code autogenerator for Golang

Jan 8, 2023

Completely type-safe compile-time mock generator for Go

Mockc Mockc is a completely type-safe compile-time mock generator for Go. You can use it just by writing the mock generators with mockc.Implement() or

Aug 25, 2022

Merge Mock - testing tool for the Ethereum Merge

MergeMock Experimental debug tooling, mocking the execution engine and consensus node for testing. work in progress Quick Start To get started, build

Oct 21, 2022

A basic lightweight HTTP client for Go with included mock features.

A basic lightweight HTTP client for Go with included mock features. Features Support almost all http method like G

May 2, 2022

📡 mock is a simple, cross-platform, cli app to simulate HTTP-based APIs.

 📡 mock is a simple, cross-platform, cli app to simulate HTTP-based APIs.

mock 📡 mock is a simple, cross-platform, cli app to simulate HTTP-based APIs. About mock Mock allows you to spin up a local http server based of a .m

May 6, 2022

A mock of Go's net package for unit/integration testing

netmock: Simulate Go network connections netmock is a Go package for simulating net connections, including delays and disconnects. This is work in pro

Oct 27, 2021

Mock API for REST!!!!

Mock API Server Introduction This app allows you to add urls and serve dummy json responses. It contains two handlers, the DummyHandler allows you to

Jun 20, 2022

Just Dance Unlimited mock-up server written on Golang and uses a popular Gin framework for Go.

BDCS Just Dance Unlimited mock-up server written on Golang and uses a popular Gin framework for Go. Features Security Authorization works using UbiSer

Nov 10, 2021

Simple mock program to set charging rate of a battery instance based on the national grid intensity api

Charger Simple mock program to set charging rate of a battery instance based on the national grid intensity api. Steps to get up and running I have cr

Nov 16, 2021
Vault mock - Mock of Hashicorp Vault used for unit testing

vault_mock Mock of Hashicorp Vault used for unit testing Notice This is a person

Jan 19, 2022
Mock-the-fck - Mock exercise for human

Mock the fck Originally, Mockery-example Example case for mockery issue #128 fil

Jan 21, 2022
Create your own mock server with just a JSON file!

Gmocker Run a blazing fast mock server in just seconds! ?? All you need is to make a json file that contains path and response mapping. See an example

Dec 21, 2022
Create your own blazing fast mock server with just a JSON file!

Gmocker Run a blazing fast mock server in just seconds! ?? All you need is to make a json file that contains path and response mapping. See an example

Dec 21, 2022
A simple mock server configurable via JSON, built using GoLang.
A simple mock server configurable via JSON, built using GoLang.

GoMock Server A simple mock server configurable via JSON, built using GoLang. How To A file name endpoint.json must be placed in the context root, wit

Nov 19, 2022
Dec 8, 2022
Sql mock driver for golang to test database interactions

Sql driver mock for Golang sqlmock is a mock library implementing sql/driver. Which has one and only purpose - to simulate any sql driver behavior in

Dec 31, 2022
HTTP mock for Golang: record and replay HTTP/HTTPS interactions for offline testing

govcr A Word Of Warning I'm in the process of partly rewriting govcr to offer better support for cassette mutations. This is necessary because when I

Dec 28, 2022
Powerful mock generation tool for Go programming language

Summary Minimock generates mocks out of Go interface declarations. The main features of minimock are: It generates statically typed mocks and helpers.

Dec 17, 2022
Mock object for Go http.ResponseWriter

mockhttp -- Go package for unit testing HTTP serving Unit testing HTTP services written in Go means you need to call their ServeHTTP receiver. For thi

Sep 27, 2022