Sign inSign up

prongbang/wiremock

By prongbang

•Updated almost 3 years ago

Minimal Mock your APIs

Image
0

809

prongbang/wiremock repository overview

⁠Wiremock Docker Pulls Image Size

Wiremock⁠ Minimal Mock your APIs

⁠How to run

⁠Run with Docker
version: '3.7'
services:
  app_wiremock:
    image: prongbang/wiremock:latest
    ports:
      - "8000:8000"
    volumes:
      - "./mock:/mock"
$ docker-compose up -d
⁠Run with Golang
$ go get -u github.com/prongbang/wiremock
$ cd project
⁠Default port 8000
$ wiremock
⁠Custom port 9000
$ wiremock -port=9000
  • Running
  _      ___                        __  
 | | /| / (_)______ __ _  ___  ____/ /__
 | |/ |/ / / __/ -_)  ' \/ _ \/ __/  '_/
 |__/|__/_/_/  \__/_/_/_/\___/\__/_/\_\


 -> wiremock server started on :8000
⁠Example Project

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

⁠Matching Routes using gorilla/mux

Read doc https://github.com/gorilla/mux#matching-routes⁠

⁠Setup project

project
├── docker-compose.yml
└── mock
    ├── login
    │   └── route.yml
    └── user
        ├── response
        │   └── user.json
        └── route.yml
⁠Login
POST http://localhost:8000/api/v1/login
Header
  Api-Key: "ed2b7d14-3999-408e-9bb8-4ea739f2bcb5"
Body
{
  "username": "admin"
  "password": "pass"
}
  • route.yml
routes:
  login:
    request:
      method: "POST"
      url: "/api/v1/login"
      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
routes:
  users:
    request:
      method: "POST"
      url: "/api/v1/user"
      header:
        Api-Key: "ABC"
      cases:
        user_history:
          body:
            action: "transaction"
          response:
            status: 200
            body_file: user-history.json
        user_check_consent:
          body:
            action: "consent"
            accept: ""
          response:
            status: 200
            body_file: user-check-consent.json
        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

* - field required.

Tag summary

Content type

Image

Digest

sha256:6f5c999d3…

Size

2.3 MB

Last updated

almost 3 years ago

docker pull prongbang/wiremock