Coder Social home page Coder Social logo

prongbang / wiremock Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 1.0 54 KB

Minimal Mock your APIs

Home Page: https://hub.docker.com/r/prongbang/wiremock

License: MIT License

Go 94.59% Dockerfile 3.01% Makefile 2.41%
golang wiremock yml docker mock-server mock-api json mock-apis

wiremock's Introduction

Wiremock Docker Pulls Image Size

Wiremock Minimal Mock your APIs

"Buy Me A Coffee"

  _      ___                        __  
 | | /| / (_)______ __ _  ___  ____/ /__
 | |/ |/ / / __/ -_)  ' \/ _ \/ __/  '_/
 |__/|__/_/_/  \__/_/_/_/\___/\__/_/\_\

 -> wiremock server started on :8000

Run with Docker

docker pull prongbang/wiremock:latest

Run with Docker Compose

version: '3.7'
services:
  app_wiremock:
    image: prongbang/wiremock:latest
    ports:
      - "8000:8000"
    volumes:
      - "./mock:/mock"
    environment:
      - ORIGIN_ALLOWED=http://localhost:9000
$ docker-compose up -d

Run with Golang

$ go install github.com/prongbang/wiremock/v2@latest

Default port 8000

$ wiremock

Custom port 9000

$ wiremock -port=9000

Example Project

https://github.com/prongbang/wiremock-example

Matching Routes using gorilla/mux

Read doc gorilla/mux

Setup project

project
├── docker-compose.yml
└── mock
    ├── login
    │   └── route.yml
    └── user
        ├── response
        │   └── user.json
        └── route.yml

Login

POST http://localhost:8000/api/v1/login
Query
  lang: "th"
Header
  Api-Key: "ed2b7d14-3999-408e-9bb8-4ea739f2bcb5"
Body
{
  "username": "admin"
  "password": "pass"
}
  • route.yml
routes:
  login:
    request:
      method: "POST"
      url: "/api/v1/login"
      query:
        lang: "th" 
      header:
        Api-Key: "ed2b7d14-3999-408e-9bb8-4ea739f2bcb5"
      body:
        username: "admin"
        password: "pass"
    response:
      status: 200
      body: >
        {"message": "success"}

User

GET   http://localhost:8000/api/v1/user/1
POST  http://localhost:8000/api/v1/user
  • route.yml
routes:
  get_user:
    request:
      method: "GET"
      url: "/api/v1/user/{id:[0-9]+}"
    response:
      status: 200
      body_file: user.json

  create_user:
    request:
      method: "POST"
      url: "/api/v1/user"
    response:
      status: 201
      body: >
        {"message": "success"}

User with multiple case

* - field required.

routes:
  users:
    request:
      method: "POST"
      url: "/api/v1/user"
      query:
        lang: "XYZ"
      header:
        Api-Key: "ABC"
      cases:
        user_accept_consent:
          body:
            action: "consent"
            accept: "Y"
          response:
            status: 200
            body_file: user-accept-consent.json
        get_profile:
          body:
            username: "*"
            userId: "*"
          response:
            status: 200
            body_file: profile-self.json

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.