Skip to content

Instantly share code, notes, and snippets.

@tvirot
Created October 25, 2017 16:19
Show Gist options
  • Save tvirot/b297416483eb48a5ee6ce66e71df91ad to your computer and use it in GitHub Desktop.
Save tvirot/b297416483eb48a5ee6ce66e71df91ad to your computer and use it in GitHub Desktop.
function handleGET (req, res) {
// Do something with the GET request
res.status(200).send('Hello World!');
}
function handlePUT (req, res) {
// Do something with the PUT request
res.status(403).send('Forbidden!');
}
/**
* Responds to a GET request with "Hello World!". Forbids a PUT request.
*
* @example
* gcloud alpha functions call helloHttp
*
* @param {Object} req Cloud Function request context.
* @param {Object} res Cloud Function response context.
*/
exports.helloHttp = function helloHttp (req, res) {
switch (req.method) {
case 'GET':
handleGET(req, res);
break;
case 'PUT':
handlePUT(req, res);
break;
default:
res.status(500).send({ error: 'Something blew up!' });
break;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment