Gets a random Psalm from the ESV API using Netlify Functions
-
Install Netlify CLI globally so you can use netlify-dev
-
You should be logged in on Netlify CLI
-
Your project should be linked to a
siteIDon Netlify (usingnetlify initornetlify link). You can confirm this has been done if you have a.netlifyfolder with astate.jsonfile containing yoursiteID. -
run
npm installto getnode-fetchwhich you'll need to fetch things inside your function -
add your api key to your netlify environmental variables in the netlify settings ui (your site > site settings > build & deploy > environmental variables)
-
create a
functions/folder at the root and put your{FUNCTION NAME}.jsfile there -
add
netlify.tomlpointing tofunctions/folder -
run
netlify devto have a local server and be able to access functions- view your site at
http://localhost:8888 - the functions will be accessible at
http://localhost:8888/.netlify/functions/function-name.
- view your site at
Basic function calling an api with javascript and node-fetch (this is the example you get when you run netlify functions:create and choose node-fetch)