An open API service indexing awesome lists of open source software.

https://github.com/plin2k/api-mocker

A simple API mocker is great for those who want to keep developing but backend hasn't prepared a working API yet.
https://github.com/plin2k/api-mocker

api go http mock websocket

Last synced: 20 days ago
JSON representation

A simple API mocker is great for those who want to keep developing but backend hasn't prepared a working API yet.

Awesome Lists containing this project

README

          

# API Mocker
[![Go Reference](https://pkg.go.dev/badge/github.com/plin2k/api-mocker.svg)](https://pkg.go.dev/github.com/plin2k/api-mocker)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/plin2k/api-mocker)

![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/plin2k/api-mocker)
![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/plin2k/api-mocker)
![GitHub last commit](https://img.shields.io/github/last-commit/plin2k/api-mocker)

## Installation
go install github.com/plin2k/api-mocker/v2@latest

### If you don't have Go
brew install go

### If there is no brew
Follow instructions - https://go.dev/doc/install

## Support Protocols
HTTP
WebSocket
gRPC - Coming soon...

## Features
Route grouping
HTTP:
Headers
Cookies
Methods:
- GET
- POST
- DELETE
- HEAD
- OPTIONS
- PATCH
- PUT
- ANY
Various responses:
- File
- Download file
- HTML file
- JSON
- XML
- TOML
- YAML
- Simple String
Delay before response
Websockets
Fake and random data
Set the maximum number of CPUs
Web documentation - Coming soon...
Authorization - Coming soon...
TLS - Coming soon...
Source file validator - Coming soon...
Api dublicator - Coming soon...
Swagger integration - Coming soon...

## Example usage

### Execute
api-mocker --help
api-mocker run --host="127.0.0.1" --port=8080 --src=api-mocker.xml --gomaxprocs=4

### Example HTTP api-mocker.xml

```xml


API v1
API Mocker Protocol - HTTP










source.xml




{"status":"success"}



{"status":"success"}












{"name":"JSON"}


```

### Example WebSocket api-mocker.xml

```xml

API V1
API Mocker Protocol - WebSocket


I'm Opened a Connection


I'm Closed a Connection


My Reply Message


My Error Message


Ping


Pong




{"msg":"every 10 sec","event":"new_chat"}



{"msg":"every 3 sec","event":"new_message"}


```

### Fakers

```
Random between dates {{ randDate "01-01-1970" "01-01-2022" }} -> "04-11-1997"
Random Bool {{ randBool }} -> true
Random String {{ randString 4 }} -> "rHdD"
Random Int {{ randInt 10 20 }} -> 15
Random Float {{ randFloat 10 1000 }} -> 43.24

Random Array Ints {{ randArrayInt 6 10 100 }} -> [15,35,22,10,39,99]
Random Array Strings {{ randArrayString 6 3 }} -> ["deZ","Zjq","sdg","pDp","dWW","WMN"]

Random Firstname (0 - male, 1 - female) {{ randFirstName 1 }} -> "James"
Random Lastname {{ randLastName }} -> "Jones"
Random Sex {{ toTitle randSex }} -> "female"

Random Email {{ randEmail }} -> "aleksandr@kalink.in"
Random Domain {{ randDomain }} -> "google.com"

Random Lang Code {{ randLangCode }} -> "en"
Random Country {{ randCountry }} -> "Japan"
Random City {{ randCity }} -> "Lefkosia"

Random JWT {{ randJWT }} -> "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsInR5MjIyMjIyMjIyMjIyMzIzMjNwIjoiSldkc2FkYXNkYXNzYVQifQ.eyJzdWIiOiIxMjM0NWRzYWRhc2RhczY3ODkwIiwibmFtZSI6IkpvZHNhZGFzZGFzZGFzZGFzZGFzZGFzZGFzZGRzYWRhc2RobiBEb2UiLCJpYXQiOjE1MTYyMzkwMjJ9.iVsrj7dQjLvA1YUUhYUGzlnfPNS2zfUcNBi-n8rK_ls"
Random Cookie {{ randCookie }} -> "id=a3fWa; Expires=Thu, 31 Oct 2021 07:28:00 GMT;"
Random UUID {{ randUUID }} -> "f7ec47d0-9a7e-11ed-a8fc-0242ac120002"
Random Hash (md5, sha1, sha256, sha512) {{ randHash "sha256" }} -> "56f3403d88c2423f711b946be61d15a7eec895635fd0e90243b6cd8526571fec"

To Title {{ toTitle ("hello") }} -> "Hello"
To Lower {{ toLower ("HELLO") }} -> "hello"
To Upper {{ toUpper ("hello") }} -> "HELLO"
Format date {{ formatDate "01-01-2014" }} -> Mon, 02 Jan 2006
```

### Usage Faker

```xml


API v1

API Mocker Protocol - HTTP.
Author {{ randFirstName 0 }} {{ randLastName }}





{
"name":"{{ randFirstName 1 }} {{ randLastName }}",
"number":{{ randInt 10 20 }},
"float": {{ randFloat 10 1000}},
"arrayInt": {{ randArrayInt 6 10 100 }},
"arrayString": {{ randArrayString 6 10 }},
"randSex": "{{ toTitle randSex }}",
"randDate": "{{ randDate "01-01-2014" "01-01-2022" }}",
"randUUID": "{{ randUUID }}",
"randHash": "{{ randHash "sha256" }}",
"randCity": "{{ randCity }}",
"randCountry": "{{ randCountry }}",
"randEmail": "{{ randEmail }}",
"randDomain": "{{ randDomain }}",
}



```