npm install @serverless-framework/google-cloud-functions
Google Cloud Functions with Node.js
import { RequestInterface, ResponseInterface, HttpStatusCode } from '@serverless-framework/core'; import { Api } from '@serverless-framework/google-cloud-functions'; // Only importing the types @types/express import { Request } from 'express'; const API_VERSION = '1.0.0'; const api = new Api({ base: '/api', }); api.get('/version', (req: RequestInterface, res: ResponseInterface) => { req.status(HttpStatusCode.OK).json({ version: API_VERSION, }); }); export const handler = api.handle((req: Request) => await api.run());
api.get('/users/:id', (req: RequestInterface<{params: {id: string}}>, res: ResponseInterface) => { req.status(HttpStatusCode.OK).json({ id: params.id, }); });
Next: Learn more about routing.