mockit is a dead simple yet powerful HTTP API mock CLI.
- Simple CLI.
- Simple configuration file (and you can split it into multiple files).
- Support response body template values.
- Buitin functions to generate random template values such as:
uuid,now,nameandemail
Get them here
[email protected]:phbpx/mockit.git
cd mockit
make mockit
sudo mv mockit ~/usr/local/bin # Or elsewhere, up to you.CLI usage:
$ mockit -h
Usage of mockit:
-config value
config file path
-port string
http port to listen on (default "8080")- Define your mocks in the configuration file:
endpoints:
- method: "GET"
url: "/accounts/:id"
response:
code: 200
headers:
Content-Type: "application/json"
body: |
{
"id": "{{ urlParam "id" }}",
"name": "{{ name }}",
"email": "{{ email }}",
"username": "{{ username }}",
"fixed": "abcd",
"createdAt": "{{ now.Format "2006-01-02T15:04:05Z" }}"
}
- method: "POST"
url: "/accounts"
response:
code: 201
headers:
Content-Type: "application/json"
body: |
{
"id": "{{ uuid }}",
"name": "{{ name }}",
"email": "{{ email }}",
"username": "{{ username }}",
"fixed": "abcd",
"createdAt": "{{ now.Format "2006-01-02T15:04:05Z" }}"
}- Run CLI:
mockit -config conf.yml -port 8080- Define your mocks in the configuration file:
endpoints:
- method: "GET"
url: "/accounts/:id"
response:
code: 200
headers:
Content-Type: "application/json"
body: |
{
"id": "{{ urlParam "id" }}",
"name": "{{ name }}",
"email": "{{ email }}",
"username": "{{ username }}",
"fixed": "abcd",
"createdAt": "{{ now.Format "2006-01-02T15:04:05Z" }}"
}- Run docker:
docker run \
-v "$(pwd):/src" \
-e MOCKIT_CONFIG="/src/conf.yml" \
-e MOCKIT_PORT="8080" \
-p 8080:8080 \
quay.io/phbpx/mockit:latest- urlParam(paramName string):
- Ex.: For URL
/accounts/:iduse{{ urlParam "id" }}to print the:idparameter.
- Ex.: For URL
- uuid:
{{ uuid }} - now:
{{ now }} - username:
{{ username }} - name:
{{ name }} - email:
{{ email }} - phone:
{{ phone }} - int:
{{ int }} - digit:
{{ digit }} - digitN(n int):
{{ digitN 4 }} - letter:
{{ letter }} - letterN(n int):
{{ letterN 10 }} - word:
{{ word }} - phrase:
{{ phrase }} - loremIpsum(n int):
{{ loremIpsum 10 }}