Skip to main content

loose-server

https://travis-ci.com/KillAChicken/loose-server.svg?branch=master

Loose server is a simple configurable server. It can be used to create temporary servers, dynamically add or remove endpoints and set responses for them from an application.

Installation

$ python -m pip install loose-server

Additional packages will be installed: Flask, flask-restful (required for the server) and requests (required for the http clients).

Documentation

Documentation for the package can be found on the Wiki.

Quickstart

Loose server has 2 variations:

  • Standalone server with API to manage rules via HTTP.

  • Flask application that can be used as a configurable mock in unit-tests.

Standalone server

A server can be started by the command

$ python -m looseserver.default.server.run
 * Serving Flask app "looseserver" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:50000/ (Press CTRL+C to quit)

API endpoints are nested to the base configuration url. By default it is /_configuration/.

from looseserver.default.client.rule import PathRule
from looseserver.default.client.response import FixedResponse
from looseserver.default.client.http import HTTPClient

client = HTTPClient(configuration_url="http://127.0.0.1:50000/_configuration/")

path_rule = client.create_rule(rule=PathRule(path="example"))

json_response = FixedResponse(
    status=200,
    headers={"Content-Type": "application/json"},
    body='{"key": "value"}',
    )
client.set_response(rule_id=path_rule.rule_id, response=json_response)

All configured endpoints have a common prefix. By default it is /routes/. The response can be obtained by the following request

$ curl http://127.0.0.1:50000/routes/example -i
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 16
Server: Werkzeug/0.15.2 Python/3.5.2
Date: Fri, 05 Apr 2019 14:08:50 GMT

{"key": "value"}

Configurable mock

Loose server can be used as a mock server in the following way

from looseserver.default.server.application import configure_application
from looseserver.default.client.flask import FlaskClient
from looseserver.default.client.rule import PathRule
from looseserver.default.client.response import FixedResponse

application = configure_application(base_endpoint="/base/", configuration_endpoint="/config/")
app_client=application.test_client()

client = FlaskClient(configuration_url="/config/", application_client=app_client)

path_rule = client.create_rule(rule=PathRule(path="example"))

json_response = FixedResponse(
    status=200,
    headers={"Content-Type": "application/json"},
    body='{"key": "value"}',
    )
client.set_response(rule_id=path_rule.rule_id, response=json_response)

response = app_client.get("/base/example")
assert response.headers["Content-Type"] == "application/json"
assert response.json == {'key': 'value'}

Metadata

Release files for loose-server 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for loose-server 1.0.0
File Size Uploaded
loose-server-1.0.0.tar.gz 14.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for loose-server 1.0.0
File Interpreter ABI Platform
loose_server-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.4 kB

Release files / loose-server-1.0.0.tar.gz

Download URL loose-server-1.0.0.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
59d8c03a214d61aa87651d8453cba8195f3a416941d4a3f6d27055bb179fc34b
BLAKE2b-256 checksum
How to use checksums
0f687ce638286d3f3ed20806b618a5a3a65f48429605b9f58bb07a7308644860
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.5.2

Release files / loose_server-1.0.0-py3-none-any.whl

Download URL loose_server-1.0.0-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2065abc796bfcaedff0b2d635e9e888e94483104e705c728e8e3b6b540beac09
BLAKE2b-256 checksum
How to use checksums
cb66b94a1177c2c10f1665a32d0d2b00c08c19b75bfae965e8da585bf34c63d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.5.2

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page