Request Mirror
Request Mirror will respond instantly with JSON containing all properties of the original request you sent to it. This is very handy for API development, webhook testing, and learning HTTP.
We use it ourselves in our test suite to make sure our service works as expected.
What is an HTTP mirror? #
An HTTP mirror, sometimes called an echo server, sends your request straight back to you. Whatever you send it (the method, the headers, the query string, the body) comes back in the response, so you can see exactly what arrived instead of guessing.
Request Mirror answers with JSON:
| Key | What it holds |
|---|---|
method |
The HTTP method used |
url |
The full request URL |
args |
Query string parameters |
headers |
All HTTP headers |
data |
The raw body |
json |
The parsed JSON payload |
form |
Form data fields |
files |
Information about uploaded files |
origin |
Your IP address |
For example:
curl -X POST https://request-mirror.ohdear.app/post \ -H "Content-Type: application/json" \ -d '{"message": "Hello World"}'
returns the method, headers and your parsed payload under json. Point a webhook at /post and you'll see the exact payload and headers the sender produces.
Why we needed to reflect HTTP requests in our test suite #
One of the many checks we offer is our uptime check. Like all our checks, we have an extensive test suite for our uptime monitoring functionality. We have tests that prove that when a site is down, we actually do warn our users.
So, in our end-to-end tests we need a site that is considered down. Instead of bringing an actual service down, wouldn't it be nice if we could just tell a website what status code it should return?
That's exactly the sort of thing that Request Mirror can do. It has a route /status/ that you can append with any status code you want. So a request to https://request-mirror.ohdear.app/status/500 will respond with status code 500, mimicking a website that is down. Try it by visiting that URL in the browser and use your developer tools to see the status code.
In our tests we can use this:
// I've simplified the test for brevity it('can send a notification when the site is down', function () { performUptimeCheck('https://request-mirror.ohdear.app/status/500'); Notification::assertSent(UptimeCheckFailedNotification::class); });
Other endpoints #
Our uptime check has many options to tailor it to your specific monitoring needs. To be able to test all these options, we added extra endpoints to Request Mirror.
Let's take a look at the ability to reflect headers:
$response = Http::withHeaders([ 'extra-header' => 'extra-value', ])->get('https://request-mirror.ohdear.app/get'); // the json response will have a headers property that contains // the `extra-header` header. $response->json('headers');
These are also available:
/get,/post,/put,/patchand/delete: one endpoint per method/anything: accepts any method, and/anything/*captures any path/headers: returns the request headers/ip: returns your IP/user-agent: returns your user agent/status/{codes}: returns the status code you ask for, or a random one from a list such as/status/200,404,500/redirect/number/{n}: redirects n times with a 302, then ends on a 204/redirect-to?url=…: a single redirect, with an optional?status=between 300 and 399 (302 by default)/latency/{ms}: adds a fixed delay of up to 1,000 ms/basic-auth: a page behind HTTP basic authentication/jsonand/xml: return a bit of sample JSON or XML
And there are a few more listed on Request Mirror.
Feel free to reach out via support@ohdear.app or on X via @OhDearApp if you have any other questions. We'd love to help!