- Endpoint that receives GET query parameters
a
&b
, which are integers, and returns the product of the two integers
Last active
April 10, 2018 16:59
-
-
Save addamh/2ce2cf24b6cedbbcd7203495f185bda3 to your computer and use it in GitHub Desktop.
Fayetteville.js // Serverless Live Demo Project
This file contains hidden or 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
'use strict'; | |
module.exports.multiply = (event, context, callback) => { | |
let { queryStringParameters: {a, b} } = event; | |
const response = { | |
statusCode: 200, | |
body: a * b | |
}; | |
callback(null, response); | |
}; |
This file contains hidden or 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
const handler = require("./handler.js"); | |
describe('Multipler', () => { | |
it('returns 64 if a and b are 8', () => { | |
const a = 8 | |
const b = 8 | |
const event = { | |
queryStringParameters: { | |
a, | |
b | |
} | |
} | |
const context = {} | |
const cb = (error, response) => { | |
const data = JSON.parse(response.body) | |
expect(data).toBe(a * b) | |
} | |
handler.multiply(event, context, cb) | |
}) | |
}) |
This file contains hidden or 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
{ | |
"name": "multiplier", | |
"version": "1.0.0", | |
"description": "", | |
"main": "handler.js", | |
"directories": { | |
"test": "tests" | |
}, | |
"scripts": {}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"serverless": "^1.26.1" | |
}, | |
"devDependencies": { | |
"jest": "^22.4.3" | |
} | |
} |
This file contains hidden or 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
service: multiplier | |
provider: | |
name: aws | |
runtime: nodejs6.10 | |
functions: | |
hello: | |
handler: handler.multiply | |
events: | |
- http: | |
path: /multiply | |
method: get |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment