What is a function ?
In Morty, a function is a classic programming language function. The only difference is that the function, depending on the runtime, will have a defined signature.
For example, a JavaScript function for the default Node.js runtime (opens in a new tab) will look like :
exports.handler = async function (req, res) {
return res.status(200).send(JSON.stringify("My first function !"));
};
Let's analyze the function signature :
req
is an Express request (opens in a new tab) object, as the runtime use Express to handle its HTTP server.res
is an Express response (opens in a new tab) object, as the runtime use Express to handle its HTTP server.
Like a classic API, you can use those two objects to retrieve information about your incoming request. Also, you have full control on the response you want to return.