Giter VIP home page Giter VIP logo

gomock's Introduction

gomock License: MIT Go Report Card Join the chat at https://gitter.im/hlts2/gomock

gomock is command line tool which makes simple API mock server. No more waiting on backend teams to deliver services.

Install

go get github.com/hlts2/gomock

Example

Create a config file

config.yml will help you get started mocking your API's.

port: 1234
endpoints:
    - request:
        path: /api/v1/todos/
        method: GET //uppercase
      response:
        code: 200
        body: todos.json
        headers:
            content-type: application/json

Request path

Paths can have variables. They are defined using the format {:id} or {:name}.

path: /api/v1/users/*/          // match: /api/v1/users/little/, /api/v1/users/tiny/, etc

path: /api/v1/users/*/name/     // match: /api/v1/users/g444/name/, /api/v1/users/f5444/name/, etc

path: /api/v1/users/*/bools/*/  // match: /api/v1/users/111/books/f343/, /api/v1/users/4444/books/d343/, etc

path: /api/v1/users?id=*        // match: /api/v1/users?id=1111, /api/v1/users?id=2222, etc

Create JSON response file

{
  "todos": [
    {
      "id": 1,
      "title": "hoge"
    },
    {
      "id": 2,
      "title": "foo"
    }
  ]
}

Start API mock server

gomock run -s config.yml

Send request

$ curl -v localhost:1234/api/v1/todos/

> GET /api/v1/todos/ HTTP/1.1
> Host: localhost:1234
> User-Agent: curl/7.51.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Wed, 20 Sep 2017 23:56:27 GMT
< Content-Length: 119
<
{
  "todos": [
    {
      "id": 1,
      "title": "hoge"
    },
    {
      "id": 2,
      "title": "foo"
    }
  ]
}

Usage

$ gomock run --help
NAME:
   gomock run - start API mock server

USAGE:
   gomock run [command options] [arguments...]

OPTIONS:
   --set value, -s value  config file (default: "config.yml")
   --tls-path value       directory to the TLS server.crt/server.key file

gomock's People

Contributors

gitter-badger avatar hlts2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gitter-badger

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.