Is there a sandbox for the Cloudflare APIs?

I’m just looking for a way that I can test the APIs in my code without having to continually clean up my tests with the dashboard.

This would be particularly useful when I am unit testing my code.



I filed a ticket, in hopes that I might get a response from Cloudflare support, but I would still value any answers the community might have.

After some activity touching on this topic, it occurs to me that I should update this question with the information that I received through the ticket I filed.

After asking the same question above this is the reply I received:

The easiest way for you is If you have a spare domain, just add it on the free plan for your testing.

This isn’t what I’d hoped for, but it seems pretty conclusive.
Later, after using this suggestion (and being sure to write appropriate cleanup code for all my unit tests), I discovered that that spare domain had been temporarily banned. I feared that it was because of adding/removing it several times in the course of the day, through my unit tests. Sure enough:

Yes, that would be the reason for the temporary ban. Unfortunately this is an automated system and no way for us to disable it. You may want to use another domain to carry on your testing until the temporary ban clears in a few hours.

Eventually, I dropped my unit tests for the API itself, and settled for a mock of my API wrapper returns the same values I received from a single test of the API. I would still highly value a sandbox for the ability to create new tests without so much setup. But it is what it is.

1 Like

So if I were to grab the endpoints and then were to edit the response I could mock a fake domain towards the classes and constructors?

I’ve also thought of using a gem called VCR and wondering if that would be the best for the tests

I’m not familiar with Ruby, so I can’t speak to VCR, but, based on it’s description, yes, that sounds like the same path I took.

Basically, I set up my mocks to expect the specific input from my tests and then reiterate the exact output that I received from the API after running it for real once. It means you do have to run every test once for real to capture the output, and then code it into your mocks.

It means that If I accidentally change something in my wrapper, or in code that uses it, the test will catch me. But it won’t catch changes that Cloudflare might make to their API. I believe Cloudflare maintains backward compatibility with new functionality, and versions the API (and the endpoint) for changes, so this is probably OK the bulk of the time. But it is worth noting that we are dependent on them doing all this and not making any mistakes.