2

Can someone tell me how to use firebase-functions.https.onRequest() for GET method? So the problem is I want to have get url like : /getData/{type}/{id}

I have tried

exports.getProduct = functions.https.onRequest("/getProduct/{type}/{id}",(request, response) =>{});

But its still not working, what I can do with that snippet code is https://firebase-url/getProduct which I cant put some parameter.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
user5436320
  • 133
  • 2
  • 17

1 Answers1

8

The https function trigger setup does not have any path matching baked in, however you can achieve this by using an Express app (as an example) for your HTTPS function:

var functions = require('firebase-functions');
var express = require('express');

var app = express();
app.get('/:type/:id', (req, res) => {
  res.send(req.params);
});

exports.getProduct = functions.https.onRequest(app);

In general you can also simply inspect req.url of the request, it is a path relative to the function name:

var functions = require('firebase-functions');

exports.getProduct = functions.https.onRequest((req, res) => {
  res.send(req.url);
});

In the above function, a GET to /getProduct/foo/bar would have a req.url equal to /foo/bar.

Michael Bleigh
  • 25,334
  • 2
  • 79
  • 85
  • Apologies to hijack this post. I noticed you work at firebase and was wondering if you could help me out here: https://stackoverflow.com/questions/45600367/firebase-cloud-function-error-could-not-handle-the-request – JamesG Aug 09 '17 at 20:50