Giter Club home page Giter Club logo

gmock-api's Introduction

gmock-api

A tool for Rest API test by mock API response. No dependencies are required.

usage

compile

$ git clone ....
$ make
  # this will show make file help 
  
$ make build
  # build main.go
  
$ make dist
  # build main.go for linux arm64
  
$ make run
  # run main.go directly
  
# 

edit config file

apis.json is a sample config file.

{
  "apis": [
    {
      "path":         ["/register", "/new"],
      "method":       ["POST", "PUT"],
      "accept":       ["application/json", "application/x-www-form-urlencoded"],
      "response":     {
        "content_type": "application/json",
        "data": {
          "act_type": 1,
          "status": "success",
          "register_id": "a99f391852caf97496e7a5ad27a7f295ecc194061b490985959472f3da3d00fb"
        },
        "status_code": 200
      }
    },
    ...
  ]
}
  • path API url, multiple support
  • method support method list
  • accept required request methods
  • response mock response
    • content_type response content type
    • data response body
    • status_code response code

test

run with --help to show usage.

$ ./build/bin/mockapi --help
Usage of ./build/bin/mockapi:
  -conf string
    	json config file (default "apis.json")
  -debug
    	debug mode
  -port int
    	agent server port (default 7001)

use your favor rest tool to access http://localhost:700/info

$ curl -s http://localhost:7001/info | jq
  # get sample

$ curl -s -H "Content-Type: application/json; charset=UTF-8" -d '{"agent_id": "tony_test_id_000", "agent_version": "1.0.1"}' http://localhost:7001/register | jq
  # post sample

Happy Hacking!

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.