Skip to content

Latest commit

 

History

History
77 lines (64 loc) · 1.65 KB

README.md

File metadata and controls

77 lines (64 loc) · 1.65 KB

Pimock

Simple Mock API using Golang

Requirement

  • golang 1.12

How To Use

  1. Create your response file under directory that same with request path
    For example you want to create mock for GET /healthz
    Create file response under responses/GET/healthz/. Folder responses is mandatory
  2. Write you header and body response HTTP inside your response file. The format is following W3 HTTP/1.1 Response.
    For example to send simple 200 OK you can do this
    HTTP/1.1 200 OK
    Content-Type: text/plain; charset=utf-8
    
    OK
    
  3. Build binary
    go build
    
  4. Run pimock
    ./pimock
    
  5. Access from port 8080
    curl localhost:8080/healthz -v
    

Features

Regex Match Path Feature

Create response file under directory with regex name, and it'll automatically find by regex Example :

responses/GET/users/([0-9]*)/response

Will match any GET request with paths

curl localhost:8080/users/1
curl localhost:8080/users/123/
curl localhost:8080/users/9898?params=value
Template Feature

Currently it only support to get path request under variable {{request.path.[i]}} and {{request.url.yourquery}} Example : Response file like this

HTTP/1.1 200 OK
Content-Type: application/json

{
  "path": "{{request.path.[1]}}"
  "params": "{{request.url.key}}"
}

Will give response

curl localhost:8080/users/123?key=value
{
  "path": "123"
  "params": "value"
}