Writing Your First Function

Now that your workspace and endpoint are set up, you’re ready to write your function.

  1. Access the Endpoint Editor: Open the endpoint you created to view example code from the selected codebase. If you want to edit the code, click the Editor button. After making changes, test your code; once it succeeds, you can publish it
  2. Write Your Code: Use JavaScript to define the logic of your function. For example, if your function takes two JSON values, a and b, and returns their sum, you might write:
    const handleRequest = async (req) => {
        const a=req.body.a||0;
        const b=req.body.b||0;
        const sum=a+b;
            return {
                'sum':sum
            }
    };
  3. Publish and Use Your Endpoint: After testing your code and confirming it succeeds, you can publish the endpoint for use. You can monitor the endpoint's performance and details in the dashboard under Endpoint Details.

Testing Your Function

Once deployed, you can test your function by calling the endpoint URL. Send a JSON payload to the endpoint and observe your function in action, receiving real-time results based on your logic.