Shared API models in API Connector
Hello everyone,
Something that has been on my mind for some time is adding the possibility of having shared API Models between calls to the API Connector. I see several advantages in this:
- Reduced number of API ‘returned values’ definitions in editor
- Reduced number of API definitions in the app’s dynamic.js, thus improved loading times
- Improved maintainability when working with API responses in bubble editor
- Reduced number of API calls, decreasing the workload on bubble server
To elaborate, imagine we are using an object called “EventPattern” in our bubble app, which is a result of a ‘Get EventPattern’ GET API call. It represents a calendar appointment with a start date and end date.
Get EventPattern
{ "results": [ { "id": "1668166870942x406523877151182500", "start": 1676347200000, "end": 1676347200000 } ] }
This ‘EventPattern’ may be changed by the user. For example the user may decide to change the start time of the appointment. To save the changes, the user performs a POST or PUT API Call.
Now, in order to update the UI properly and reflect changes, we need the updated object from our API connector. This means another GET API call. But what if the backend responded to our POST/PUT call with the updated object immediately, thus eliminating the need for another GET call? Well bad luck, because we are using ‘Get EventPattern’ in bubble, we can’t use the response data from our POST/PUT API call, even though it is in the exact the same format.
To sum things up, the current process looks something like this:
- User gets data from API Connector using a GET API call
- User updates data in the UI
- User presses “Save” and saves data using a POST/PUT API Call
- Backend responses to POST/PUT with the updated object
- As we can not use the response object, we need to perform another GET API Call
So how could we indicate to bubble that the response from our POST/PUT API call is the same as from a GET API call? It could look something like this:
Because we define the response to the POST/PUT API call as being the same as to a GET call, we can use the responses from either API call to populate Groups or bubble elements that have ‘Type of content’ set to ‘Get EventPattern’.
I currently do not have any statistics about how many bubble users use API connector, so this might be a very niche request.
Please feel free to add anything to this post if you have any other ideas on improving API Connector or generally think this might be a good idea.