Skip to main content

Mock HTTP server

Project description

Turq is a tool for semi-interactively testing and debugging HTTP clients. Somewhat like httpbin, but more interactive and flexible. Turq runs a small HTTP server that is scriptable in a Python-based DSL. It lets you quickly set up mock URLs that respond with the status, headers and body of your choosing.

Usage

Run this on a machine with Python 2.6 or 2.7:

$ pip install turq
$ python -m turq
Listening on port 13085
Try http://localhost:13085/+turq/

Open http://localhost:13085/+turq/ in your Web browser. You should see a text area. This is the Turq console. Enter this and click “Commit”:

path('*').text()

Now open http://localhost:13085/ (without the +turq/) in another tab. You should see a plain-text greeting.

Examples

Redirect from root to an index.php, which returns a simple HTML page after 2 seconds of “loading”:

path('/').redirect('/index.php')
path('/index.php').delay(2).html()

Imitate a JSON API with JSONP and cross-origin support:

path('/api/v1/*').cors().json()

Prompt for basic HTTP authentication, then serve up a page with some text (ignoring credentials):

with path('/secret') as r:
    r.first().basic_auth()
    r.then().lots_of_html()

Imitate round-robin balancing between three backends, one of which is slow:

with path('/') as r:
    r.first().html()
    r.next().html()
    r.next().delay(5).html()

Serve XML from /product.xml, reflecting the passed id parameter:

@path('/product.xml')
def process(req, r):
    r.xml('<product><id>%s</id></product>' % req.query['id'][0])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

turq-0.1.0.tar.gz (9.7 kB view details)

Uploaded Source

File details

Details for the file turq-0.1.0.tar.gz.

File metadata

  • Download URL: turq-0.1.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for turq-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ffa39e7f5965632bcd527a297bd1fccd929061a99219a0c26f1eeac32c27e4f0
MD5 bde9296f04015d5ee42af46c7cb697dc
BLAKE2b-256 5e99f546d67902fd1b90e88aeef8c8ef767f570967bc60d9b36619efe9a144e3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page