Categorygithub.com/juan131/api-mock
repository
0.4.1
Repository: https://github.com/juan131/api-mock.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

REST API mock

A Golang service that can be customized to mock REST APIs

Usage

Run the API mock using Docker:

docker run --rm -p 8080:8080 juanariza131/api-mock

The API mock will be available at http://localhost:8080/v1/mock.

Configuration

The API mock can be configured with the following environment variables:

VariableDescriptionDefault
PORTThe port to listen on8080
LOG_LEVELThe log levelinfo
API_KEYAPI key to authenticate requests via X-API-KEY header``
API_TOKENBearer token to authenticate requests``
FAILURE_RESP_BODYThe response body to return when mocking a failure{"error":{"message":"failed request","code":1005,"id":"[random-value]"}}
FAILURE_RESP_CODEThe HTTP status code to return when mocking a failure400
SUCCESS_RESP_BODYThe response body to return when mocking a success{"success": "true"}
SUCCESS_RESP_CODEThe HTTP status code to return when mocking a success200
SUCCESS_RATIOThe ratio of success to failure responses1.0
METHODSThe HTTP methods to mockGET,POST
RESP_DELAYThe response delay (in milliseconds)0
SUB_ROUTESThe sub routes to mock``
RATE_LIMITThe API rate limit (requests per second)1000
RATE_EXCEEDED_RESP_BODYThe response body to return when mocking a rate exceeded{"error":{"message":"rate limit exceeded","code":1004,"id":"[random-value]"}}

Build

You can build the API mock binary with the following command:

make build

The binary will be available in the out directory.