Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Callable Cloud Functions better than HTTP functions?

With the latest Firebase Update callable functions were introduced. My question is whether this new way is faster than the "old" http triggers and if it is more secure.

I have no expertise in this field, but I think the HTTP vs HTTPS might make a difference.

This is interesting to me because if the callable functions are faster, they have that advantage, but their disadvantage lies in the nature of flexibility: They cannot be reached by other sources.

If the callable functions have no advantages in terms of speed or security I do not see a reason to switch it up.

like image 770
creativecreatorormaybenot Avatar asked Mar 25 '18 12:03

creativecreatorormaybenot


People also ask

What is the difference between onCall HTTP callable and onRequest HTTP request functions?

onRequest creates a standard API endpoint, and you'll use whatever methods your client-side code normally uses to make. HTTP requests to interact with them. onCall creates a callable. Once you get used to them, onCall is less effort to write, but you don't have all the flexibility you might be used to.

Does Firebase use HTTP?

You can connect an HTTP function to Firebase Hosting. Requests on your Firebase Hosting site can be proxied to specific HTTP functions. This also allows you to use your own custom domain with an HTTP function. Learn more about connecting Cloud Functions to Firebase Hosting.

Why should I use cloud functions?

Cloud Functions removes the work of managing servers, configuring software, updating frameworks, and patching operating systems. The software and infrastructure are fully managed by Google so that you just add code. Furthermore, provisioning of resources happens automatically in response to events.

When should I use Firebase cloud function?

You should use Cloud Functions for Firebase if you're a developer building a mobile app or mobile web app. Firebase gives mobile developers access to a complete range of fully managed mobile-centric services including analytics, authentication and Realtime Database.


1 Answers

Callable functions are exactly the same as HTTP functions, except the provided SDKs are doing some extra work for you that you don't have to do. This includes, on the client:

  1. Handling CORS with the request (for web clients)
  2. Sending the authenticated user's token
  3. Sending the device instance id
  4. Serializing an input object that you pass on the client
  5. Deserializing the response object in the client

And on the backend in the function:

  1. Validating the user token and providing a user object from that
  2. Deserializing the input object in the function
  3. Serializing the response object in the function

This is all stated in the documentation. If you are OK with doing all this work yourself, then don't use callables. If you want this work done automatically, then callables are helpful.

If you need direct control over the details of the HTTP protocol (method, headers, content body), then don't use a callable, because it will hide all these details.

There are no security advantages to using callables. There are no speed improvements.

like image 67
Doug Stevenson Avatar answered Sep 18 '22 22:09

Doug Stevenson