Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Latest commit

 

History

History
48 lines (38 loc) · 853 Bytes

001-api-mocking.md

File metadata and controls

48 lines (38 loc) · 853 Bytes

API Mocking

Aaron is working on a Python script that will hit an API endpoint his coworker is still iterating on. His coworker sends over some mocks with the API response structure.

Using this he generates a Routes file:

route {
  host = "example.com"
  path = "/"
  type = "http"
}

And a mock file, at /mocks/example.com/index.mock.

{
  "field1": 0,
  "field2": "string"
}

Now he can work on his script before the site is up, while still using the full network stack of his program.

import requests

proxies = {
    'http': 'http://squid.proxy:8888',
    'https': 'http://squid.proxy:8888',
}

resp = requests.get(
    'https://example.com',
    proxies=proxies,
    verify='/usr/local/share/ca-certificates/ca.pem'
)
print(resp.json())
python test.py
### {'field1': 0, 'field2': 'string'}