Created
October 25, 2017 16:19
-
-
Save tvirot/b297416483eb48a5ee6ce66e71df91ad to your computer and use it in GitHub Desktop.
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
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