Sign inSign up

natenho/mockaco

By natenho

•Updated about 1 year ago

HTTP mock server, useful to stub services and simulate dynamic API responses with .net c# scripting

Image
1

100K+

natenho/mockaco repository overview

⁠Quick reference

⁠What is Mockaco?

Mockaco is an HTTP-based API mock server with fast setup, featuring:

  • Simple JSON-based configuration
  • Pure C# scripting - you don't need to learn a new specific language or API to configure your mocks
  • Fake data generation - built-in hassle-free fake data generation
  • Callback support - trigger another service call when a request hits your mocked API
logo

⁠How to use this image

⁠Running the demo

The default image ships with a sample "hello" mock:

$ docker run -it --rm -p 5000:5000 natenho/mockaco

Mockaco can be accessed by any HTTP client via http://localhost:5000

$ curl -iX GET http://localhost:5000/hello/docker
HTTP/1.1 200 OK
Date: Wed, 21 Jun 2019 05:10:00 GMT
Content-Type: application/json
Server: Kestrel
Transfer-Encoding: chunked

{
	"message": "Hello docker!"
}

⁠Running and creating your own mocks

The best way to use the image is by creating a directory on the host system (outside the container) and mount this to the /app/Mocks directory inside the container.

  1. Create a data directory on a suitable volume on your host system, e.g. /my/own/mockdir.
  2. Start your mockaco container like this:
$ docker run -it --rm -p 5000:80 -v /my/own/mockdir:/app/Mocks natenho/mockaco

The -v /my/own/mockdir:/app/Mocks part of the command mounts the /my/own/mockdir directory from the underlying host system as /app/Mocks inside the container, where Mockaco by default will read its mock JSON files.

  1. Create a request/response template file named PingPong.json under /my/own/mockdir folder:
{
  "request": {
	"method": "GET",
	"route": "ping"
  },
  "response": {
	"status": "OK",
	"body": {
	  "response": "pong"
	}
  }
}
  1. Send a request and get the mocked response, running:
$ curl -iX GET http://localhost:5000/ping
HTTP/1.1 200 OK
Date: Wed, 21 Jun 2019 05:10:00 GMT
Content-Type: application/json
Server: Kestrel
Transfer-Encoding: chunked

{
	"response": "pong"
}

For advanced usage scenarios, like scripting and fake data generation, refer to the docs⁠.

Tag summary

Content type

Image

Digest

sha256:e2bcd4935…

Size

51.1 MB

Last updated

about 1 year ago

docker pull natenho/mockaco