Reputation: 15663
What is the recommended approach for versioning HTTPS Callable cloud functions in Firebase to prevent breaking client functionality after deploying a new version of an endpoint?
'm seeking a solution similar to versioning REST APIs, such as incorporating the version string into the endpoint URL (e.g., /api/v1/customers/3) or utilizing custom MIME types in the Header information.
Upvotes: 3
Views: 333
Reputation: 83103
AFAIK there is no recommendation on this point in the Cloud Functions for Firebase documentation.
With Callable Cloud Functions, you can mimic the two approaches you describe in your question for API endpoint versioning.
You can very well have several Callable Cloud Functions with a version number in their name, e.g.:
exports.doSomethingInThebackEndv1 = functions.https.onCall((data, context) => {
// ...
});
exports.doSomethingInThebackEndv2 = functions.https.onCall((data, context) => {
// ...
});
You can add the version to the object you pass to the function when calling it from your front-end. For example with the JS SDK:
var doSomethingInThebackEnd = firebase.functions().httpsCallable('doSomethingInThebackEnd');
doSomethingInThebackEnd({ foo: 'bar', version: 1 })
.then((result) => {...});
Then in the back-end:
exports.doSomethingInThebackEnd = functions.https.onCall((data, context) => {
const version = data.version;
// do different things depending on the version value
});
I admit that it is not an out-of-the-box scalable solution and that it may request a lot of manual operations in case of many different versions...
Upvotes: 1