Created
September 16, 2020 08:41
-
-
Save batyrf/64f8ea82cfca440bf813730457f66cbc to your computer and use it in GitHub Desktop.
SImple Rest Api with Firestore and Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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