Codetje docs

Getting started

The quickest way to a running module is the console's editor, which builds and publishes in your browser. After that, this page shows the same thing from the command line, in AssemblyScript and in Rust.

In the browser

  1. Sign in at codetje.com. The first time, you choose a username, which becomes your namespace.

  2. Choose New module, and give it a name, such as hello.

  3. Replace the code with:

    import { Request, Response } from "@codetje/assemblyscript";
    
    export function handle(req: Request): Response {
      const name = req.param("name");
      return Response.text("Hello, " + (name !== null ? name : "world") + "!\n");
    }
    
  4. Build and publish. The editor publishes a new version and points the preview tag at it, so you can try it at https://<you>--hello--preview.codetje.app/?name=Ada.

  5. When it works, move stable to it. https://<you>--hello.codetje.app now serves that version.

New packages are private: only you can run them, so a browser that isn't sending your credentials gets an error. To serve a page to everyone, make the package public in its settings. See Settings and secrets.

The editor keeps your draft in the browser until it's published, and opening the module later loads the source of its live version.

From the command line

You need Node.js for the AssemblyScript SDK and rt, the Codetje CLI.

rt isn't released as a binary yet. Build it from the runtime-runner repository with cargo install --path crates/cli. Then sign in:

  1. Create an access token at accounts.codetje.com/tokens. You confirm it from an email, and the token is shown once.
  2. Run rt login and paste it. rt whoami shows the namespaces you can publish to.

AssemblyScript

The SDK isn't on npm yet either, so install it from a checkout of the repository. In a new directory:

npm init -y
npm install --save-dev --install-links /path/to/runtime-runner/sdk/assemblyscript
mkdir assembly

Put the handle function from above in assembly/index.ts, then build and publish:

npx codetje-as build . -o build/hello.wasm
rt publish build/hello.wasm <you>/[email protected] --source build/hello.source.json --tag preview

--source stores the source with the version, so the console's editor can open it and anyone who can read the package can check that it builds to the same bytes. --tag preview points preview at the new version. Once you're happy with it:

rt tag set <you>/hello stable preview

The AssemblyScript SDK guide covers the API.

Rust

Any language that compiles to a wasi:http component works. In Rust, with the wstd crate:

rustup target add wasm32-wasip2
cargo new hello && cd hello
cargo add wstd
use wstd::http::{Body, Error, Request, Response};

#[wstd::http_server]
async fn main(request: Request<Body>) -> Result<Response<Body>, Error> {
    let path = request.uri().path().to_owned();
    Ok(Response::new(format!("Hello from {path}\n").into()))
}
cargo build --release --target wasm32-wasip2
rt publish target/wasm32-wasip2/release/hello.wasm <you>/[email protected] --tag preview

See Other languages.

What's next

  • Writing modules: what a module can export, and the sandbox it runs in.
  • Settings and secrets: environment variables, fetching from other servers, and making a package public.