Skip to main content

Mock HTTP server

Project description

Turq is a small HTTP server that can be scripted in a Python-based language. Use it to set up mock HTTP resources that respond with the status, headers, and body of your choosing. Turq is designed for quick interactive testing, but can be used in automated scenarios as well.

Lets you do things like

“RESTful API” resource with cross-origin support:

if route('/v1/products/:product_id'):
    if GET or HEAD:
        json({'id': product_id, 'inStock': True})
    elif PUT:
        json(request.json)      # As if we saved it
    elif DELETE:
        status(204)
    cors()      # Handles preflight requests automatically

Redirect to an index.php, which serves a gzipped, cacheable page after 3 seconds of “loading”:

if path == '/':
    redirect('/index.php')

if path == '/index.php':
    sleep(3)
    html()
    gzip()
    header('Cache-Control', 'max-age=3600')

Stream server-sent events:

header('Content-Type', 'text/event-stream')
for i in range(9000):
    sleep(1)
    chunk('data: event number %d\r\n\r\n' % i)

Built-in editor

You don’t even need to create any files, just use the built-in Web editor:

screenshot.png

Get it now

In any Python 3.4+ environment:

$ pip3 install turq
$ turq

Read the docs for more.

Thanks

BrowserStack have kindly provided a free subscription for testing Turq.

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.3.1.tar.gz (213.3 kB view details)

Uploaded Source

Built Distribution

turq-0.3.1-py2.py3-none-any.whl (133.3 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for turq-0.3.1.tar.gz
Algorithm Hash digest
SHA256 4db8747eedaa4928618dd18376a80550f37a2a3823495934eef234e84c17fcfe
MD5 cfb3e8132bdb763426d91922b2a2dd9c
BLAKE2b-256 f0752a942041a5e098a1580089b78fb90ebbbf79d4d883a25139ca2c3941574b

See more details on using hashes here.

File details

Details for the file turq-0.3.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for turq-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f83f1ee7c61bb5d74b6feb2c417aca3a0bb15954a9409c733432ce0d858ec95a
MD5 d63f785e6774cd57b137fe60f765ef26
BLAKE2b-256 a03b26e887df04d75bef9c6f6ad12c25e77a753e1bfd946e9628d3a542db40ff

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