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.
â
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
â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.
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.
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.â
- In your Retool account, click on the resources option in the header and open the resource where your production environment can be found.
- 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.
- If youâve made any changes to your API, make sure you save.
- 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.
- 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).â
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.
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.
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.
â