Skip to main content

Programmable HTTP server for testing

Project description

Simple programmable HTTP API server.

build coverage docs

The server is programmable using elements from the HTTP Archive (HAR) specification originally developed by Jan Odvarko and the W3C web-performance working group. It was never moved beyond draft in the W3C. Jan Odvarko has maintained the specification on his blog. I created this project after discovering the mockbin service created by Mashape (now KongHQ). Unfortunately mockbin does not meet my exact needs.

Usage

The primary use case is to return programmed responses to specified requests. The response is POSTed to service along with a matching request. Both are specified as HAR objects – the request is a HAR request and the response is a HAR response

POST /responses HTTP/1.1
Host: 127.0.0.1:8080
Content-Type: application/json
Content-Length: 733

{
   "request": {
      "method": "GET",
      "url": "http://example.org/status",
      "httpVersion": "HTTP/1.1",
      "cookies": [],
      "headers": [],
      "queryString": [],
      "postData": {},
      "headersSize": -1,
      "bodySize": 0
   },
   "response": {
      "status": 200,
      "statusText": "OK",
      "httpVersion": "HTTP/1.1",
      "cookies": [],
      "headers": [
         {"name":"Content-Type", "value":"application/json"}
      ],
      "content": {
         "mimeType": "application/json",
         "encoding": "json",
         "text": {
            "service": "my-service",
            "status": "ok"
         }
      },
      "redirectURL": "",
      "headersSize": -1,
      "bodySize": -1
   }
}

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 49
Link: <http://127.0.0.1:8080/hosts>; rel=host-map; method=GET
Link: <http://127.0.0.1:8080/requests>; rel=requests; method=GET
Link: <http://127.0.0.1:8080/responses>; rel=add-response; method=POST
Link: <http://127.0.0.1:8080/responses>; rel=clear-responses;
  method=PURGE

{
   "effective_url": "http://127.0.0.1:32443"
}

After this message is sent, the service will respond to GET /status on port 32443 with the registered response:

GET /status HTTP/1.1
Host: 127.0.0.1:32443

HTTP/1.1 200 OK
Content-Type: application/json

{
  "service": "my-service",
  "status": "ok"
}

Project details


Download files

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

Files for har-server, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size har_server-0.0.1-py3-none-any.whl (4.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size har-server-0.0.1.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page