Giter Club home page Giter Club logo

mocker's Introduction

Mocker

A simple and lightweight tool to create and share mocked services for development or test environment.

Usage

Mocker could be used through the command line or docker container.

CLI

Installation

$ go get github.com/maykonlf/mocker/cmd/mocker

Flags

  • -addr: mocker server API address (default ":8081")
  • -f: mock service spec file path (default "./mocker.yaml")

Start mock

Go to a path containing the mocker.yaml spec file and run the following command on your terminal:

$ mocker

Then you can make requests to your mocked service and it will respond as configured on your mocker.yaml file.

Docker

$ docker run -d -v .:/mocker -p 8081:8081 maykonlf/mocker

Mock Specs - mocker.yaml

  • api: describes mocked API specs
    • routes: list of matching API routes.
    • methods: list of matching HTTP methods (must be in lowercase)
    • response: describes the response mocker should return when the received requests match the specs above.
      • status: HTTP response status code
      • headers: key-value response headers
      • body: response body string
      • time: time to wait before responding to the request - useful to simulate API processing time (ex: 200ms, 1s)

Example

# mocker.yaml

api:
  - routes:
    - /v1/books
    - /v2/books
    methods:
    - get
    response:
      status: 200
      headers:
        Content-Type: application/json
      body: >
        [{
            "id: "7d619e9b-9fd2-4abb-b9b4-cfa5811e97a5",
            "title": "Clean Code: A Handbook of Agile Software Craftsmanship"
        }, {
            "id: "46c1bc9f-2ae0-4d73-bf9d-531fa1898537",
            "title": "Clean Architecture: A Craftsman's Guide to Software Structure and Design"
        }, {
            "id: "c8daf68a-5a28-4438-91c1-9f5835ad6439",
            "title": "Refactoring: Improving the Design of Existing Code"
        }]
      time: 200ms

mocker's People

Contributors

maykonlf avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.