Retool's Nifty API Generator: Generate Fake API Data for your Staging App

Retool's API Generator is a speedy way of creating varied dummy data through a REST API and can be used to fill gaps whilst waiting for backend changes, create mock apps and even create a staging environment. This tutorial will show you how.

Retool's Nifty API Generator: Generate Fake API Data for your Staging App

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).

‍

This tutorial will go through:

  • Why use Retool’s API Generator?
  • How to build a custom Retool API and connect it to your Retool app  
  • Why use a staging environment?
  • How to use your new custom-generated API to develop a staging environment 
  • How to create a Retool application with your new Staging/Production environments

 

What's the API Generator and why use it?

‍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! 

How to build a custom Retool API 

‍To get started building your REST API, go to https://retool.com/api-generator/. Then, follow the steps below.

Retool's API generator settings

‍

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!

 

How to connect your new custom API in Retool 

‍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.

Retool's API generator API endpoints

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”

‍

Image showing the Retool Resource '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

Configure REST API resource in Retool settings

 

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.

 

How to use your new custom-generated API to develop a staging environment 

📌 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.‍

  1. In your Retool account, click on the resources option in the header and open the resource where your production environment can be found.
  2. The first thing you will notice is that, if you try to click on the staging tab, it isn’t possible. That is because you need to create a staging environment. To enable this, click on the “Enable Staging” toggle in the top corner of the screen.
  3. If you’ve made any changes to your API, make sure you save.
Retool REST API staging tabs resource window
  1. Retool will shoot you this pop-up - conversely, if you have already saved your resource you can click ‘Proceed. Don’t Save’, if you’re not sure if you have, click ‘Got it!’ and make sure to hit ‘Save Changes’ again. This is just a reminder from Retool that you don’t need to worry much about.
Pop-up showing save option within Retool resource
  1. Your final step is to connect your staging API. Input the necessary data to your resource to connect to your staging environment. If you are using Retool’s API Generator, you only need the Base URL as shown in the picture below. If you need help connecting your Retool Custom API, head back to the tutorial section “How to connect your new custom API in Retool”, (and if you haven’t yet created one, follow the steps in section two).‍
Rest API Resource highlighting location of Base URL

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!

Why Use A Staging API? 

‍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.

‍

How to create a Retool application with your new Staging/Production environments

‍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.

Gif showing the Retool app switching between staging and production

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.


đŸ’„
At Bold Tech, we specialize in building great internal tools, fast. We are obsessed with building apps that make your teams happier and more productive. In our blog, you can learn all about how to build better business software for more satisfied employees, or get in touch to chat to us about what you're looking to build.

‍


Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Bold Tech Blog.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.