Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Google Cloud Functions

Table of contents

  1. Installation
  2. Usage
    1. Parameters

Installation

npm install @serverless-framework/google-cloud-functions

Google Cloud Functions with Node.js


Usage

  
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());

Parameters

api.get('/users/:id', (req: RequestInterface<{params: {id: string}}>, res: ResponseInterface) => {
        req.status(HttpStatusCode.OK).json({
        id: params.id,
    });
});

Next: Learn more about routing.