Docs/Tools

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 extensive testsuite to make sure our service works as expected.

Why we needed to reflect HTTP requests in our testsuite

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 to have a site available that is considered down. Instead of bringing an actually 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:

And there are a few more listed on Request Mirror.

Was this page helpful?

Feel free to reach out via [email protected] or on X via @OhDearApp if you have any other questions. We'd love to help!