Is there a way to quickly change an app's many REST API calls to a new resource?

I have apps that are used by external clients, and each of them point to a different REST API URL.

Since there is a single app codebase, the default resource is always "API", but each client actually targets a different URL.

What I've done so far is require each client to create a new ReTool account and I just change the "API" resource URL, but it's a pain to keep the app updated in each account, and I now have cases where the same app is installed for different APIs for the same client so they don't want separate accounts.

Is there a simple way to update all references to the "API" resource in an app and change it to "API2" ? Doing it manually for each call is not manageable.

Thanks

Hello @francis!

Could you help me better understand with more detailed example? A resource is meant to connect a app via queries with a source of data (Such as a table).

Any changes you want to make in an API's URL should be done in the query that are accessing a given resource. Or by making new queries if you don't want to have to manually change out previous queries for new ones.

If you want to replace one resource with another resource, you just need to go into the query's Resource options, as shown below.

To change a resource instead of replacing it with a new resource, you should go one level above the flow of data and change the resource itself.

You can do this in the resource tab from the home page as shown below.

If you want to change a dynamic value in many locations, one option would be a global variable, however, those are scoped to a single Retool app. You can read more about global variables here. This could be used for part of a URL string if you use javascript interpolation.

Also check out this article in our docs on reusable queries here.

My use case is:

  • App A targets "API" resource which points to "URL A".
  • A copy of App A targets the same "API" resource (because it's the same code), but "API" needs to point to "URL B".
  • Another copy of App A needs to target "URL C".

Right now what I do is manually change the code in each instance of App A to use a separate resource. If the app has just 2 or 3 queries that's fine, but when there are 30+ it takes considerable time, and I either have to do this for every app after a code change (ouch), or manually duplicate all changes to each app separately (re-ouch). Either way it's a maintenance nightmare.

There has to be a better way to handle this but I haven't found it yet.

Thanks,

Francis

@Francis Thank you for the elaboration this helps a ton.

You can re-use Queries across multiple apps as outlined in our documentation here where you can save a query that you will use often to your query library.

You can create dynamic query routes using {{ }} in the REST API query route, and from there you can give each app a unique global variable or config var, which you can then reference in multiple queries on the same app.

You can have dynamic query URLs using javascript to grab a single or multiple variables that you want to use dynamically in a large number of queries in a single app using config vars, which is available for users on the team, business and enterprise plans.

Unfortunately there is not a way to have dynamic resources and you will have to manually create a REST API resource in each app for each unique source of data.