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

Overview

Project Logo

mock

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

GitHub Downloads Latest Release Build Status Contributions Welcome

About mock

Mock allows you to spin up a local http server based of a .mock.yaml file. Preferably mock is used per project and a .mock.yaml file is created at the root of a repository.

Installation

Binaries

If you prefer grabbing mock its binaries, download the latest from the the GitHub releases page.

Brew

❯ brew tap bschaatsbergen/mock
❯ brew install mock

Chocolatey (Not supported yet)

❯ choco install mock

Usage

Running mock is very easy, by simply running the below command you tell mock to translate the .mock.yaml in the current working directory to an http server that by default runs under port 7070. Use the -p flag to change the default port.

❯ mock serve

📝 using config file: .mock.yaml
📡 starting mock on :7070, exit to stop

To bring you up to speed, we allow you to run the below command in order to generate an exampe .mock.yaml in the current working directory.

❯ mock init

🎉 generated '.mock.yaml' in: /home/bruno/Projects/MyNewApi

The generated .mock.yaml configuration looks as following. It's made up of a list of endpoints, each containing a resource path, http method, response and http status code.

# Example .mock.yaml config
Endpoints:
  - Resource: /city/1
    Method: GET
    Response: '{ "Id": 1, "Name": "Albuquerque", "Population": 559.374, "State": "New Mexico" }'
    StatusCode: 200

  - Resource: /city
    Method: POST
    Response: '{ "Name": "Albuquerque", "Population": 559.374, "State": "New Mexico" }'
    statusCode: 200

  - Resource: /city/1
    Method: PUT
    Response: '{ "Id": 1, "Name": "Albuquerque", "Population": 601.255, "State": "New Mexico" }'
    StatusCode: 200

  - Resource: /city/1
    Method: DELETE
    StatusCode: 204

After running mock serve you can verify whether the routes are available

❯ curl -i -X GET 'http://localhost:7070/city/1'
HTTP/1.1 200 OK
Content-Type: application/json
Date: Tue, 19 Oct 2021 13:25:47 GMT
Content-Length: 80

{ "Id": 1, "Name": "Albuquerque", "Population": 559.374, "State": "New Mexico" }

License

This project is licensed under the MIT License - see the LICENSE file for details.

Issues
  • Add the ability to define a port in the .mock.yaml.

    Add the ability to define a port in the .mock.yaml.

    Currently if I want to run multiple mock sessions under multiple ports, I have to pass the -p flag per project. It would be nice to have the ability to define a port in the .mock.yaml that overwrites the default 7070 port.

    enhancement 
    opened by bschaatsbergen 1
  • Wrap binaries in snapcraft package as part of release

    Wrap binaries in snapcraft package as part of release

    It would be useful for linux users to package the binaries in a snap package as not everyone bothers with brew or downloading the binaries. There's a .goreleaser.yaml at the root of the repository which supports snapcraft.

    See https://goreleaser.com/customization/snapcraft/ as a reference.

    enhancement 
    opened by bschaatsbergen 1
  • #1 - Add ability to overwrite default port from .mock.yaml

    #1 - Add ability to overwrite default port from .mock.yaml

    Optional property that users can specify in the .mock.yaml to overwrite the default address (:7070).

    enhancement 
    opened by bschaatsbergen 0
  • Windows installer

    Windows installer

    choco ,MSI or both ?

    opened by zahycs 1
Owner
Bruno Schaatsbergen
Bruno Schaatsbergen
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

Seb C 100 Jan 8, 2022
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

Taj 0 Nov 16, 2021
Fast cross-platform HTTP benchmarking tool written in Go

bombardier bombardier is a HTTP(S) benchmarking tool. It is written in Go programming language and uses excellent fasthttp instead of Go's default htt

Максим Федосеев 3k Jan 11, 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

Tv 22 Aug 5, 2020
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

Andres Mijares 1 Oct 19, 2021
A tool that integrates SQL, HTTP,interface,Redis mock

Mockit 目标:将mock变得简单,让代码维护变得容易 分支介绍 main 主分支,覆盖了单元测试 light 轻分支,去除了单元测试,简化了依赖项,方便其他团队使用 常见Mock难点 不同中间件,mock库设计模式不一致,学习代价高,差异化明显 mock方案强依赖服务端,无法灵活解耦 单元测试

SHIHUO 12 Jan 7, 2022
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

Miguel Alexandre 0 Jan 9, 2022
Extremely flexible golang deep comparison, extends the go testing package and tests HTTP APIs

go-testdeep Extremely flexible golang deep comparison, extends the go testing package. Latest news Synopsis Description Installation Functions Availab

Maxime Soulé 241 Jan 10, 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

DATA-DOG 4.1k Jan 10, 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.

Juno Inc. 436 Dec 24, 2021
ESME is a go library that allows you to mock a RESTful service by defining the configuration in json format

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.

Sumit Tokkar 3 Mar 2, 2021
mockery - A mock code autogenerator for Golang

mockery - A mock code autogenerator for Golang

Vektra 3.2k Jan 10, 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

Ananto 46 Jan 13, 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

Ananto 45 Dec 24, 2021
Vitaly Berg 7 Aug 10, 2021
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

Geon Kim 29 May 23, 2021
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

Diederik Loerakker 17 Jan 4, 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

Lucas Wolf 1 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

null 2 Nov 17, 2021