---
title: Functions handlers reference
description: Discover how to implement function handlers for Serverless Functions in Scaleway.
tags: serverless functions cron crontab schedule cronjob
dates:
  validation: 2025-10-27
  posted: 2024-04-09
---

A handler is a routine/function/method that processes specific events. Upon invoking your function, the handler is executed and returns an output.

To learn how to package a function and its dependencies in a zip file, refer to the [dedicated documentation](/serverless-functions/how-to/package-function-dependencies-in-zip).

## Handler syntax

<Tabs>
  <TabsTab label="Python">
  
    For Python functions, the handler must be written in the `<folder>/<file>.<function_name>` format.

    - If the `handle` function is defined in a single file named `handler.py`: the handler name will be `handler.handle`.

    - If the `handle` function is defined in a file named `handler.py` in a root folder: the handler will be `handler.handle`.

    - If the `handle` function is defined in a file named `handler.py` within a folder (for example, `myFunction/handler.py`): the handler will be `myFunction/handler.handle`.

    #### Python handler example

    ```py
    def handle(event, context):
    return {
        "body": {
            "message": 'Hello, world',
        },
        "statusCode": 200,
    }
    ```
  </TabsTab>

  <TabsTab label="Node">

    For Node functions, the handler must be written in the `<folder>/<file>.<function_name>` format.

    - If the `handle` function is defined in a single file named `handler.js`: the handler name will be `handler.handle`.

    - If the `handle` function is defined in a file named `handler.js` in a root folder: the handler will be `handler.handle`.

    - If the `handle` function is defined in a file named `handler.js` within a folder (for example, `myFunction/handler.js`): the handler will be `myFunction/handler.handle`.

    #### Node handler example

    ```js
    export {handle};

    function handle (event, context, cb) {
        return {
            body: process.version,
            statusCode: 200,
        };
    };
    ```
  </TabsTab>
  
  <TabsTab label="PHP">

    For PHP functions, the handler must be written in the `<folder>/<file>.<function_name>` format.

    - If the `handle` function is defined in a single file named `handler.php`: the handler name will be `handler.handle`.

    - If the `handle` function is defined in a file named `handler.php` in a root folder: the handler will be `handler.handle`.

    - If the `handle` function is defined in a file named `handler.php` within a folder (for example, `myFunction/handler.php`): the handler will be `myFunction/handler.handle`.

    #### PHP handler example

    ```php
    <?php
    function handle($event, $context) {
      return [
        "body" => phpversion(),
        "statusCode" => 200,
      ];
    }
    ```
  </TabsTab>

  <TabsTab label="Go">

    For Go, the handler must be written in the `<folder>/<function_name>` format:

    - If the `Handle` function is defined in a `handler.go` file in a root folder: the handler name will be `Handle`.

    - If the `Handle` function is defined in a `handler.go` file (for example, `myFunction/handler.go`): the handler will be `myFunction/Handle`

    <Message type="note">
    With Go, the method name must be capitalized.
    </Message>

    #### Go handler example

    ```go
      package myfunc
      
      import (
          "encoding/json"
          "net/http"
      )
      
      // Handle - Handle event
      func Handle(w http.ResponseWriter, r *http.Request) {
          response := map[string]interface{}{
            "message": "We're all good",
          }
      
          responseBytes, err := json.Marshal(response)
          if err != nil {
            w.WriteHeader(http.StatusInternalServerError)
            return
          }
      
          // Set the header explicitly depending the returned data
          w.Header().Set("Content-Type", "application/json")
      
          // Customize status code.
          w.WriteHeader(http.StatusOK)
      
          // Add content to the response
          _, _ = w.Write(responseBytes)
      }
      ```
  </TabsTab>

  <TabsTab label="Rust">

    For Rust, the handler must be written in the `<folder>/<function_name>` format:

    - If the `handle` function is defined in a `handler.rs` file in a root folder: the handler name will be `handle`.

    - If the `handle` function is defined in a `handler.rs` file (for example, `myFunction/handler.rs`): the handler will be `myFunction/handle`

    <Message type="note">
    With Rust, the method must be exported using the `pub` keyword.
    </Message>

    #### Rust handler example

    ```rust
      use axum::{
          body::Body, extract::Request, response::Response,
      };
      use http::StatusCode;
      
      pub async fn handle(_req: Request<Body>) -> Response<Body> {
          Response::builder()
              .status(StatusCode::OK)
              .header("Content-Type", "text/plain")
              .body(Body::from("Hello world!"))
              .unwrap()
      }
      ```
  </TabsTab>
</Tabs>
