Firebase HTTP functions


(Jack Hobbs) #1

I need help on firebase HTTP functions.
I want to use HTTP as API for fetching data from client side so that there will be no load on clients end.


(Karthik Kamalakannan) #2

Hey @Jack_Hobbs
I believe @varun is the right person to answer this question. :slight_smile:


(Agrata Arya) #3

ok sir…Thanks a lot…


(Varun Raj) #4

Hi @Jack_Hobbs

What data you’re trying to fetch from client side?


(Jack Hobbs) #5

Hi varun,
I am a novice Firebase Developer and trying to do things simple.
I want to fetch details of customer crosspond to their ID or get a JSON object. So that there will be smooth trassmission.


(Varun Raj) #6

Hello Jack,

Here is the small snippet from one of our implementation which I feel might help you.

function getGroupInfo(options) {
   firebase.database()
           .ref('groupInfo')
           .once('value')
           .then(function(snapshot){
              var info = snapshot.val();
              options.onSuccess({info: info});
           });
}

function upcomingEventDetailsHandler(app) {
  console.log('Came to Upcoming Event Details');
  const fromFallback = app.getArgument('fromFallback');
  const timeQuery = app.getArgument('time-query');
  const venueQuery = app.getArgument('venue-query');
  var message,
      statement,
      statements = [];

getGroupInfo({
    onSuccess: function(data) {
      console.log(timeQuery);
      console.log(venueQuery);
      if (timeQuery) {
        statement = "It is happening on " + moment(data.info.next_event.time).format("MMM Do YY") + ".";
        statements.push(statement);
      }

if (venueQuery) {
        var venue = data.info.next_event.venue || "yet to be announced.";
        statement = "The venue is " + venue;
        statements.push(statement);
      }

message = statements.join(" ");
      console.log(message);
      app.ask(message);
    }
  })
}

Attaching the article for your reference