Created
February 18, 2020 10:43
-
-
Save ahmedghazi/c87170bb5d622df36d5831bf69eafe50 to your computer and use it in GitHub Desktop.
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
import axios from "axios" | |
export async function handler(event, context) { | |
try { | |
const response = await axios.get("https://icanhazdadjoke.com", { headers: { Accept: "application/json" } }) | |
const data = response.data | |
return { | |
statusCode: 200, | |
body: JSON.stringify({ msg: data.joke }) | |
} | |
} catch (err) { | |
console.log(err) // output to netlify function log | |
return { | |
statusCode: 500, | |
body: JSON.stringify({ msg: err.message }) // Could be a custom message or object i.e. JSON.stringify(err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment