Skip to content
Franklin Chieze edited this page Oct 16, 2020 · 3 revisions
func(name?: string)

The func decorator specifies that a TypeScript class method should be converted to a Firebase cloud function. This decorator must be the first firefuncs decorator on that method.

parameters

example

import { func, onHttpsRequest } from 'firefuncs';

export class Records {
    @func()
    @onHttpsRequest()
    public async hello(req, res) {
        res.send('Hello World!');
    }

    @func('postEndpoint')
    @onHttpsRequest('/', {
        method: 'post'
    })
    public async save(req, res) {
        try {
            const db = req.firestore.db;
            await db.collection('records').add({ ...req.body });
            res.send('Added records successfully');
        } catch (error) {
            res.send({ error })
        }
    }
}