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 2 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.

egghead
egghead
~ a minute ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today