SLC.RUNDocs

Quick Start

Deploy your first stateful serverless function in minutes.

1. Create a Worker

Create a new file called `worker.ts`:

export default async function handler(ctx: {
  actorId: string;
  state: {
    get(): Promise<Record<string, any>>;
    set(partial: Record<string, any>): Promise<void>;
  };
  request: {
    method: string;
    body?: any;
    headers?: Record<string, string>;
  };
}): Promise<Response | any> {
  // Your handler logic
  const currentState = await ctx.state.get();
  
  if (ctx.request.method === "POST") {
    await ctx.state.set({
      ...currentState,
      ...ctx.request.body,
    });
  }
  
  return {
    message: "Hello from actor!",
    state: await ctx.state.get(),
  };
}

2. Configure Your App

Create `slc.config.json` in your project root:

{
  "name": "hello-world-app",
  "entry": "./worker.ts"
}

Note: The `apiBaseUrl` field is optional. If not specified, the CLI will use the endpoint from your `~/.slcrc` configuration file (defaults to `https://api.slc.run`).

  • name: Your app name (used in the invoke URL)
  • entry: Path to your worker file (relative to the config file)
  • apiBaseUrl (optional): The API endpoint URL (defaults to production API)

3. Deploy Your App

slc deploy

This will bundle your `worker.ts` into a single JavaScript file, upload it to the regional node, and register it as a deployable app.

You'll see output like:

Bundling worker.ts...
Uploading to https://api.slc.run...
✓ App 'hello-world-app' deployed successfully
  Version: 1
  Created: 12/1/2024, 10:30:00 AM

Invoke via: slc invoke hello-world-app <actorId>

4. Invoke Your App

Using the CLI (Recommended)

slc invoke hello-world-app user-123 --data '{"message":"hi there"}'

Using curl with versioned API

curl -X POST https://api.slc.run/v1/invoke/my-project/hello-world-app/user-123 \
  -H "Content-Type: application/json" \
  -H "x-slc-api-key: sk_your_api_key" \
  -d '{"message":"hi there"}'

The handler will load or create the actor with ID `user-123`, pass the request body to your handler, update the actor's state, and return a JSON response with version metadata.

Handler Context

  • `actorId`: The unique identifier of the actor instance
  • `state.get()`: Returns the current state as a JSON object
  • `state.set(partial)`: Merges `partial` into the current state
  • `request`: The incoming HTTP request (method, body, headers)

Return Value

Your handler can return:

  • • A JSON-serializable object (will be sent as JSON with 200 status)
  • • A `Response` object (for full control over status and headers)

Next Steps

Learn more about the CLI, SDK, and API: