Coming up with sample data is an absolute pain in the a...ddress book. I’m well enough acquainted with every John, Jane, and Mary, but while I should be using my brain power on my current project, I’m instead wasting 30 minutes trying to ensure I have a perfect mix of gendered names, seemingly accurate dates, and varied personal details. Or, on a worse day, I have somehow forgotten every other first name in existence - the Doe family it is. The Retool API Generator, however, is the natural remedy to my itching need for variety. It is incredibly simple and, better yet, it is available 100% free of charge to everyone – no need to even have a Retool account to use it (but we think you should make one anyway).
Retool's API Generator is a speedy way of creating varied dummy data through a REST API. The API has GET, POST, PUT, PATCH and DELETE endpoints, so can do most things your real API can, and you can call this API from wherever you need it (a mobile app, using cURL, Postman, etc.).
There are a variety of reasons Retool’s API Generator might come in handy:
1. Preventing Work Stoppages
Whether your engineer hasn’t completed the backend or you want to get started while you wait for database access, the API generator will prevent unnecessary work stoppages and let you focus on actually developing.
2. Showing Proof of Concept Or Creating A Mockup
If you are trying to quickly assemble a project demonstrating the value-add of a project and don’t want to spend the time connecting or even don’t have access to the data you will be using, the API generator is a quick and easy way to generate test data for a mock app.
3. Having A Set Of Data To Create A Staging Environment
Another beneficial use of the API generator is creating a staging environment. If you, as a developer, want to be able to have full connectivity and capabilities (read AND write) without worrying about damaging your actual dataset, you can use the API Generator to create up to 150 rows of dummy data. Say goodbye to those heavy-query-load-induced cold sweats and hello to fail-safe testing data!
To get started building your REST API, go to https://retool.com/api-generator/. Then, follow the steps below.
1. Create a new column
2. Name your column and choose from 100+ different types of data*
3. Choose the number of rows you want to have (max of 150)
4. Give your API a name
5. Click generate
*IMPORTANT NOTE FOR STAGING ENVIRONMENTS: If the column headers in your custom API for staging don’t perfectly match the headers in your production API, you will run into issues with your app when switching between environments. If you are creating data for staging, make sure to check against your existing API.
Congratulations! You have created a custom API!
For those that are familiar with connecting APIs in Retool, you’ll be reassured to know it’s one of the simpler versions out there - all you’ll need is your base URL from the generator.
If you are less comfortable with the wonderful world of API connections, you can work through the simple steps below.
1. Below the “Generate NEW API” in the API Generator are all the endpoints you would ordinarily expect. Copy the endpoint best suited for your needs and get logged into your Retool account. If you don’t have any specific filtering needs, you are most likely going to use the first GET endpoint for reading data, and the POST for writing it.
2. Once you are logged into your Retool account, click on the resources option in the header
3. Click the “Create new” button on the right-hand side of the screen
4. When selecting the resource type, under the APIs selection group, click “REST API”
5. Give your REST API a name
6. Paste copied information from step 1 into the “Base URL”
NOTE: you do not need the curl or quotations in the base URL
7. Click the “Create resource” button in the lower right hand of your screen
If you are looking to connect your API via bash scripting instead? Check out this video from Retool.
Now that you have added your Custom API as a resource in Retool, you are ready to get started with using your data! Head to the next section for how to use this to create a staging environment.
You can find more information on connecting to API’s in Retool in their documentation.
NOTE: Staging environments are not available for users in the “Free” pricing tier. You will have to upgrade to “Startup” to be able to utilize these features.
As a developer, having a second set of data while building applications is essential to avoid heavy-load query mishaps and overwriting critical data. Not sure you need one? Skip to section: ‘Why Use a Staging API’ to learn more. This section will walk through how to add a staging environment within Retool.
NOTE: I have used a free Plant API connection as a placeholder for the production REST API connection.
4. Click the “Save changes” button in the bottom right corner of the screen.
Now, when you go into your app, you can switch between your dummy data in your staging environment and, once you've connected to your real API, your production environment, using the toggle in the top right of the screen.
Don’t forget! If the column headers in your custom staging API and your ‘real’ production environment don’t perfectly match you will run into issues with your app when switching between environments as Retool will fail to recognise your references. Make sure to double (or triple) check your column headers match before creating your app, as this can be very difficult to troubleshoot further down the line. Pay close attention to singular vs. plural and capitalization!
There are many reasons why developing a staging environment is a very important first step when creating a project. Here are the key ones:
1. Protecting Live Data
While you are working with critical data and testing features of your Retool app, you don’t want the thought of destroying real data to even cross your mind. By working exclusively in a staging environment, you won’t have to worry!
2. Show And Tell
Are you presenting your app to individuals who shouldn’t have access to sensitive data? If you, as a developer, want to put your app on the internet or simply outside the organization, it would be prudent to utilize a staging environment as a means of hiding proprietary data.
3. Working With Individuals With Different Access To Sensitive Data
If an individual doesn’t need the information that they are using, they shouldn’t have access to it - and this same principle applies in many different industries. A staging environment (especially one utilizing Retool’s API Generator) will allow for the partitioning of data so that your engineers or developers aren’t accessing data that they shouldn’t, whether that’s financial, personal or other sensitive information that shouldn’t be shared.
Now that you’ve created the production and staging resource query above, let’s put it to use.
First, create a new Retool application. Once you’ve opened up a new app, start by connecting to the resource you created above in a new query.
After you have connected to your resource with the staging option enabled, a new toggle will appear in the top corner of the screen that shows which environment you are using.
To demonstrate (and verify that it is working), let’s add a table and a couple of charts to our Retool app.
As you switch between the staging and production toggle, you will see your data changing between the two REST APIs you created (did we mention? ONLY if your column headers in both environments match).
So, using the Retool Custom API Generator, you have just created a staging environment to protect your real data!
Let’s quickly review everything this tutorial has covered:
1. Building a Custom API using Retool’s API Generator
2. Building a new resource in Retool that connects to the Custom API
3. Creating a staging and production environment in Retool (and why)
Congratulations! May all your future production environments be less screwed and your dummy data ever more varied.