Mock API reference

This worker exposes a small mock API for testing clients. Responses are simple JSON objects that are easy to inspect and assert against.

Unless noted otherwise, every endpoint returns a JSON body in this shape:

{
  "value": <any>
}

Overview

Available endpoints:

Random value endpoints

GET /boolean

Returns a random boolean wrapped in a value field.

Request
GET /boolean
Example response
{
  "value": true
}

GET /integer

Returns a random integer between 0 and 99.

Request
GET /integer
Example response
{
  "value": 57
}

GET /string

Returns a random colour string from a fixed list.

Request
GET /string
Example response
{
  "value": "purple"
}

GET /array

Returns an array of three random colours.

Request
GET /array
Example response
{
  "value": ["red", "green", "blue"]
}

/post endpoint

POST /post

Accepts a JSON body and returns a simple API-style wrapper with status, statusText and data.

Request
POST /post
Content-Type: application/json

{
  "name": "Alice",
  "score": 12
}
Example response
{
  "value": {
    "status": 200,
    "statusText": "OK",
    "data": {
      "name": "Alice",
      "score": 12
    }
  }
}

If a method other than POST is used, the worker returns a 405 Method Not Allowed-style object.

/object endpoint

/object is a small CRUD-style mock endpoint. It always returns an object with status, statusText and data wrapped in the outer value field.

GET /object?b64=<string>

GET accepts a Base64-encoded JSON string through the b64 query parameter. The decoded JSON is returned in data. This allows you to control exactly what the mock endpoint returns without using a request body.

Example request
Encoded JSON:
{"foo":"bar","id":42}
Request:
GET /object?b64=eyJmb28iOiJiYXIiLCJpZCI6NDJ9
Example response
{
  "value": {
    "status": 200,
    "statusText": "OK",
    "data": {
      "foo": "bar",
      "id": 42
    }
  }
}

POST /object

Echoes the JSON request body and marks it as created.

Request
POST /object
Content-Type: application/json

{
  "id": 42,
  "name": "Han Solo"
}
Example response
{
  "value": {
    "status": 201,
    "statusText": "Created",
    "data": {
      "id": 42,
      "name": "Han Solo"
    }
  }
}

PUT /object

Echoes the JSON request body and marks it as updated.

Request
PUT /object
Content-Type: application/json

{
  "id": 42,
  "name": "Jon Snow"
}
Example response
{
  "value": {
    "status": 200,
    "statusText": "OK",
    "data": {
      "id": 42,
      "name": "Jon Snow"
    }
  }
}

DELETE /object

Simulates a delete. Returns a 204 No Content-style object with data: null.

Request
DELETE /object
Example response
{
  "value": {
    "status": 204,
    "statusText": "No Content",
    "data": null
  }
}

Unknown routes

If you call a path that is not implemented, the worker returns this HTML page instead of JSON. Use one of the endpoints above to test your client.