Sign inSign up

dvlprtech/api-mockr

By dvlprtech

•Updated about 4 years ago

Just another API mocker that can be configured to response random and specific data.

Image
0

1.3K

dvlprtech/api-mockr repository overview

codecov Code size License CI Last Commit Docker version

⁠api-mockr

Just another API mocker that can be configured to response random and specific data. It can help testing integrations with third parties.

Currently, only REST API responses are supported.

⁠Getting started

docker run --rm --name mockr -it -p 3003:3003 dvlprtech/api-mockr

We should see something like:

Launching api-mockr...
[🟢 api-mockr] Server running at: http://0.0.0.0:3003

To stop de server, if the container is running in interactive mode, press [Ctrl+C]

The application default port es 3003, to use custom config files we can map a volume on /config container directory and to pass specific parameters to the application we can pass them to the command line or use the environment variable MOCKR_PARAMS (Notice the missing E in "MOCKR_").

In the following example we are passing the --verbose option parameter and the local config file: /my-local-configs-paths/user-crud.yml:

# The  /config/user-crud.yml is the container path to config ile
docker run --rm --name mockr -it -p 3003:3003 -v /my-local-configs-paths:/config dvlprtech/api-mockr --verbose --config=/config/user-crud.yml

Using the env MOCKR_PARAMS:

# The  /config/user-crud.yml is the container path to config ile
MOCKR_PARAMS="--verbose --config=/config/user-crud.yml"
docker run --rm --name mockr -it -p 3003:3003 -v /my-local-configs-paths:/config -e MOCKR_PARAMS="$MOCKR_PARAMS" dvlprtech/api-mockr

We can also use the API Mockr container with a docker-compose descriptor, just like whatever other backend or with a more complex platform for container orchestation like Kubernetes or similar. In these cases we can configure API Mockr like a third party API REST, to simulate the behavior of whatever integration our application needs, It's specially useful to create integration tests where we need to interact with an external service, so we can customize the response for different services exactly as we expect the external service responses.

⁠Testing the server

We can use whatever http client tool we prefer, i.e: curl, postman, ...

With curl, a simple call would be:

curl  'localhost:3003/user?_pretty=1'

Other example with POST and payload:

curl -XPOST -H "content-type: application/json" 'localhost:3003/whatever/32?foo=bar&_pretty=1' -d '{
 "username": "dalton32"
 "fullName": "Johnny F. Dalton"
}'

For further details about config options and application parameters please refer to the GitHub repo⁠

Tag summary

Content type

Image

Digest

sha256:990881bbb…

Size

44.9 MB

Last updated

about 4 years ago

docker pull dvlprtech/api-mockr