Skip to content

Instantly share code, notes, and snippets.

@batyrf
Created September 16, 2020 08:41
Show Gist options
  • Save batyrf/64f8ea82cfca440bf813730457f66cbc to your computer and use it in GitHub Desktop.
Save batyrf/64f8ea82cfca440bf813730457f66cbc to your computer and use it in GitHub Desktop.
SImple Rest Api with Firestore and Functions
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.marvel = functions.https.onRequest(async (req, res) => {
try {
const listResult = await admin.firestore()
.collection('marvel')
.get()
.then(snapshot => snapshot.docs.map(x => x.data()))
res.json({ data: listResult })
} catch (e) {
const message = e.message;
res.json({ data: null, error: message });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment