> ## Documentation Index
> Fetch the complete documentation index at: https://iii.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Expose an HTTP Endpoint

> How to register a function and expose it as a REST API endpoint.

## Goal

Expose a Function as an HTTP endpoint so external clients can call it via REST.

## Steps

### 1. Enable the REST API worker

Make sure `iii-config.yaml` has the REST API worker enabled:

```yaml title="iii-config.yaml" theme={"theme":{"light":"catppuccin-latte","dark":"dark-plus"}}
  - name: iii-http
    config:
      port: 3111
      host: 127.0.0.1
      default_timeout: 30000
      concurrency_request_limit: 1024
      cors:
        allowed_origins:
          # To allow all origins, use '*':
          # - '*'
          - localhost
        allowed_methods:
          - GET
          - POST
          - PUT
          - DELETE
          - OPTIONS
```

### 2. Register the Function

<Tabs>
  <Tab title="Node / TypeScript">
    ```typescript title="http-endpoint.ts" theme={"theme":{"light":"catppuccin-latte","dark":"dark-plus"}}
    import {registerWorker, Logger} from 'iii-sdk'

    const iii = registerWorker(process.env.III_URL ?? 'ws://localhost:49134')

    iii.registerFunction('users::create', async (req) => {
      const logger = new Logger()
      const { name, email } = req.body
      const user = { id: crypto.randomUUID(), name, email }
      logger.info('User created', { userId: user.id })
      return { status_code: 201, body: user }
    })
    ```
  </Tab>

  <Tab title="Python">
    ```python title="http_endpoint.py" theme={"theme":{"light":"catppuccin-latte","dark":"dark-plus"}}
    import os
    import uuid

    from iii import Logger, register_worker

    iii = register_worker(os.environ.get("III_URL", "ws://localhost:49134"))


    def create_user(req):
        logger = Logger()
        name = req["body"]["name"]
        email = req["body"]["email"]
        user = {"id": str(uuid.uuid4()), "name": name, "email": email}
        logger.info("User created", {"userId": user["id"]})
        return {"status_code": 201, "body": user}


    iii.register_function("users::create", create_user)
    ```
  </Tab>

  <Tab title="Rust">
    ```rust title="http_endpoint.rs" theme={"theme":{"light":"catppuccin-latte","dark":"dark-plus"}}
    use iii_sdk::{register_worker, InitOptions, Logger, RegisterFunction};
    use serde_json::{json, Value};
    use tokio::signal;

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let url = std::env::var("III_URL").unwrap_or_else(|_| "ws://127.0.0.1:49134".to_string());
        let iii = register_worker(&url, InitOptions::default());

        let reg = RegisterFunction::new_async("users::create", |req: Value| async move {
            let logger = Logger::new();
            let name = req["body"]["name"].as_str().unwrap_or("");
            let email = req["body"]["email"].as_str().unwrap_or("");
            let user_id = uuid::Uuid::new_v4().to_string();
            logger.info("User created", Some(json!({ "userId": user_id })));
            Ok(json!({
                "status_code": 201,
                "body": { "id": user_id, "name": name, "email": email }
            }))
        });
        iii.register_function(reg);

        println!("HTTP endpoint ready on POST /users");
        signal::ctrl_c().await?;

        Ok(())
    }
    ```
  </Tab>
</Tabs>

### 3. Register the HTTP trigger

<Tabs>
  <Tab title="Node / TypeScript">
    ```typescript title="http-trigger.ts" theme={"theme":{"light":"catppuccin-latte","dark":"dark-plus"}}
    iii.registerTrigger({
      type: 'http',
      function_id: 'users::create',
      config: { api_path: '/users', http_method: 'POST' },
    })
    ```
  </Tab>

  <Tab title="Python">
    ```python title="http_trigger.py" theme={"theme":{"light":"catppuccin-latte","dark":"dark-plus"}}
    iii.register_trigger({
        "type": "http",
        "function_id": "users::create",
        "config": {"api_path": "/users", "http_method": "POST"},
    })
    ```
  </Tab>

  <Tab title="Rust">
    ```rust title="http_trigger.rs" theme={"theme":{"light":"catppuccin-latte","dark":"dark-plus"}}
    iii.register_trigger(RegisterTriggerInput {
        trigger_type: "http".into(),
        function_id: "users::create".into(),
        config: json!({ "api_path": "/users", "http_method": "POST" }),
        metadata: None,
    })?;
    ```
  </Tab>
</Tabs>

### 4. Try it

```bash theme={"theme":{"light":"catppuccin-latte","dark":"dark-plus"}}
curl -X POST http://127.0.0.1:3111/users \
  -H "Content-Type: application/json" \
  -d '{"name": "Alice", "email": "alice@example.com"}'
```

## Result

Your Function is now accessible as `POST /users` on port 3111. The `http` trigger handles request parsing and response serialization automatically.

<Info title="Request and Response types">
  HTTP-triggered Functions receive an `ApiRequest` and should return an `ApiResponse`. See the [SDK Reference](../api-reference/sdk-node) for type details.
</Info>
