Quickstart
Create a free account
To get started, create a free account on the sign up page!
Building functions
Below is a high-level overview of how to structure your Buildfunctions handler functions and their responses. The various examples demonstrate a consistent pattern: a main entry point function named handler that returns (or echoes) a response containing at least a body. Beyond that, you can optionally include a status code and headers in the natural syntax the language supports.
1. The handler Function
- Naming: Your main function must be named
handler. This name is how Buildfunctions identifies which function to invoke when your code runs. - Purpose: The
handlerfunction is your function’s entry point. It contains the logic you want to run whenever your function is invoked. You can write other helper functions, but only thehandlerwill be called automatically.
2. The Response Format
Your handler function must provide a response that can be returned to the caller. While the exact syntax differs by language, the structure is essentially the same:
- Body (Required): The main content you want to return.
- Status Code (Optional): A numeric HTTP status code (e.g., 200 for success, 500 for a server error).
- Headers (Optional): Custom headers, such as Content-Type, can also be included.
Note: Cache-related functionality will be available soon.
Example Response Structures:
- JavaScript
async function handler(event) { return { statusCode: 200, headers: { 'Content-Type': 'text/plain' }, body: 'Hello, world!', }; } - TypeScript
async function handler(event: any): Promise<{ statusCode: number; headers: { [key: string]: string }; body: string; }> { return { statusCode: 200, headers: { 'Content-Type': 'text/plain' }, body: 'Hello, world!', }; } - Python
def handler(event, context): return { "statusCode": 200, "headers": {"Content-Type": "text/plain"}, "body": "Hello, world!" } - Go
package handler import "fmt" func handler() string { fmt.Println("Hello, world!") return "Hello, world!" } - Shell
handler() { echo "Hello, world!" }
Omit constructs like if __name__ == "__main__" in Python or handler() in JavaScript, as the platform will handle invocation.
- Python
def handler(event, context): return { "statusCode": 200, "headers": {"Content-Type": "text/plain"}, "body": "Hello, world!" } # Do NOT include: # if __name__ == "__main__": # response = handler() # print(response) - JavaScript
function handler() { return { statusCode: 200, headers: { 'Content-Type': 'text/plain' }, body: 'Hello, world!', }; } // Do NOT include: // handler(); // Unnecessary;
Note: Buildfunctions is currently in its beta stage. If you encounter any issues or have specific syntax requirements, please reach out and contact us, and we’ll work to address them.