Firebase Function onCall vs onRequest

2022-01-28T19:45:36.000Z

The onCall is a straight http function. The onRequest goes via the SDK and will handle some or the boilerplate code you need for CORS and authentication. Rule of thumb: Use onRequest when you don’t need to call from the web or via http.

My of the examples are for onRequest this is what you will want to do if you use the SDK. It handles a lot of parsing and security for you. The SDK really helps so you won’t need to worry about CORS or be bogged down in security. The disadvantage is that it is a little harder to test because you can’t call it via http.

Use onCall when you want to do it all yourself. This includes parsing parameters and handling security. It’s great if it is what you need but only use it when you are not using the SDK, or it needs to be called from outside the SDK. Google has SDKs for most popular languages including my preferred languages: Flutter and Vue3.

Firebase documentation.