feature (#2): add joke api endpoint

This commit is contained in:
Ben Hong 2022-02-22 17:14:07 -08:00
parent 06bd1e1dff
commit 07b9861415
2 changed files with 22 additions and 0 deletions

15
netlify/functions/joke.js Normal file
View File

@ -0,0 +1,15 @@
// Jokes provided from the lovely folks at https://icanhazdadjoke.com
import jokes from './jokes.json'
export const handler = (event) => {
// Generates a random index based on the length of the jokes array
const randomIndex = Math.floor(Math.random() * jokes.length)
const randomJoke = jokes[randomIndex]
// Netlify Functions need to return an object with a statusCode
// Other properties such as headers or body can also be included.
return {
statusCode: 200,
body: JSON.stringify(randomJoke),
}
}

View File

@ -0,0 +1,7 @@
[
"My New Years resolution is to stop leaving things so late.",
"Child: Dad, make me a sandwich. Dad: Poof! You're a sandwich.",
"The invention of the wheel was what got things rolling",
"What kind of music do mummy's like? Rap",
"What do you get when you cross a chicken with a skunk? A fowl smell!"
]