Sign inSign up

chisanan232/pymock-api

By chisanan232

β€’Updated almost 2 years ago

πŸ•ΈπŸ€–πŸ‘Ί A tool to set up web server for mocking API easily and humanly.

Image
0

171

chisanan232/pymock-api repository overview

⁠PyMock-API

PyMock-API⁠ is a tool for mocking APIs easily and quickly by configuration only.

⁠How to use it?

You need to configure a YAML file to set API details. Let's demonstrate a sample configuration for you:

mocked_apis:
  foo_home:
    url: '/foo'
    http:
      request:
        method: 'GET'
      response:
        value: 'This is Foo home API.'

From above settings, it means setting an API:

  • URL path: /foo
  • Allow HTTP request method GET without parameters
  • If request successfully, it would return value This is Foo home API..

And save above setting as file /User/foo/mock-api-demo/api.yaml.

Let's set up an instance to provide service:

docker run --name mock-server \
           -v /User/foo/mock-api-demo:/mit-pymock-api \
           -p 9672:9672 \
           -d \
           pymock-api:v0.1.0

Try to send a HTTP request to the service:

curl http://127.0.0.1:9672/foo

Congratulations! You successfully configure and set up a web server for mocking API.

⁠Environment variables

When you set up a PyMock-API instance by Docker, you can pass one or more environment variables to set its settings.

CONFIG_PATH

This is an option variable. It would set the file path where it should use to configure the APIs and set up web server. In default, its value is api.yaml.

WEB_FRAMEWORK

This is an option variable. The web framework PyMock-API would use to set up web server to mock APIs. It only accepts 3 type values:

  • auto:

    This is the default value. It would automatically detect which web framework PyMock-API could use in current runtime environment.

  • flask:

    Use Python web framework Flask⁠ to set up web server.

  • fastapi

    Use Python web framework FastAPI⁠ to set up web server.

WORKERS

This is an option variable. How many workers it should use to handle HTTP requests in the web server. In default, its value is 1.

LOG_LEVEL

This is an option variable. Set the log level to let web server site show log message which is not below it. In default, its value is info.

⁠Quick reference

Tag summary

Content type

Image

Digest

sha256:c1818892b…

Size

439.3 MB

Last updated

almost 2 years ago

docker pull chisanan232/pymock-api:v0.2.0