When to use the onCall or onRequest Firebase Cloud functions

Jorge Vergara
InstructorJorge Vergara
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

Firebase has two methods for creating HTTP functions, onRequest follows a REST pattern and onCall gives you access to the Firebase JavaScript SDK.

Instructor: Firebase has two different ways to create HTTP functions. One is using the onRequest() functions, and the other one is using the onCall() function. Both of these functions create an HTTP endpoint you can call.

The big difference is that the onRequest() follows more the regular REST API, where you send data to the endpoint, and you here get their request, their response, and you work with that, like in most Node.js applications.

The onCall() is a special wrapper on top of that that lets you use the Firebase JavaScript SDK from the client side, which will handle most of the complex part for you, like handling already passing the authentication state of the user without you having to send any tokens or anything like that. They both work as a general guideline. I usually use the onRequest() when I'm talking server to server, like when I'm creating functions that another server is trying to talk to.

I use the callable functions when I'm calling those APIs from the UI. That way, I don't have to handle the JWT tokens or anything like that. I just use the JavaScript SDK, and they send the proper tokens that I need for the authentication.