Hello, World!
The inevitable Hello World example.
exports.handler = (event, context, callback) => { callback(null, { statusCode: 200, body: "Hello, World ๐๐ป๐จ๐ด" }); };
Hi there! This is a playground to test out Netlifyโs Lambda Functions.
You can browse the code for this site on GitHub, or play around with the code yourself deploying a copy to Netlify.
The inevitable Hello World example.
exports.handler = (event, context, callback) => { callback(null, { statusCode: 200, body: "Hello, World ๐๐ป๐จ๐ด" }); };
Generating random emoji.
import emoji from 'node-emoji'; export async function handler() { return { statusCode: 200, body: JSON.stringify(emoji.random()) }; }
Generating list dog photos.
For this gallery, we will query a free Unsplash API to obtain super cute images of dogs and display them in a masonry. Head to Unsplash, signup to create a new app and get an access key.
const axios = require('axios') exports.handler = async (event, context, callback) => { const apiRoot = "https://api.unsplash.com" const accessKey = process.env.ACCESS_KEY const collections = `collections='3816141,1154337,1254279'` const clientId = `client_id=${accessKey}` const doggoEndpoint = `${apiRoot}/photos/random?${clientId}&count=${10}&${collections}` try { const res = await axios.get(doggoEndpoint) const result = { statusCode: 200, body: JSON.stringify({ images: res.data} ) } return callback(null, result) } catch (error) { return callback(error); } }