> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.hyjal.cloud/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.hyjal.cloud/_mcp/server.

# Deploy a Rust API

> Build a wasi:http JSON API with cargo component, deploy it to Hyjal's Rust lane, and verify it with curl in about ten minutes.

This tutorial builds a JSON API in Rust as a WebAssembly component and deploys
it to Hyjal on the Rust lane. You end with a public HTTPS endpoint that returns
JSON, proven with `curl`.

Time: about ten minutes. You need the [`hyjal` CLI](/reference/cli), a
logged-in session, and a Rust toolchain with the
[`wasm32-wasip2`](/languages/rust) target and `cargo component`.

## 1. Create the component

Scaffold a new component crate:

```bash
$ cargo component new acme-api --lib
$ cd acme-api
```

Implement the `wasi:http` incoming handler. The component returns a JSON body
for every request.

```rust
// src/lib.rs
use bindings::exports::wasi::http::incoming_handler::Guest;
use bindings::wasi::http::types::{
    Fields, IncomingRequest, OutgoingResponse, ResponseOutparam,
};

struct Component;

impl Guest for Component {
    fn handle(_request: IncomingRequest, response_out: ResponseOutparam) {
        let headers = Fields::new();
        headers
            .set("content-type", &[b"application/json".to_vec()])
            .unwrap();

        let response = OutgoingResponse::new(headers);
        response.set_status_code(200).unwrap();

        let body = response.body().unwrap();
        let stream = body.write().unwrap();
        stream
            .blocking_write_and_flush(br#"{"service":"acme-api","ok":true}"#)
            .unwrap();
        drop(stream);

        OutgoingResponse::finish(body, None).unwrap();
        ResponseOutparam::set(response_out, Ok(response));
    }
}

bindings::export!(Component with_types_in bindings);
```

## 2. Build locally

Confirm the component compiles to a wasip2 artifact:

```bash
$ cargo component build --release
   Compiling acme-api v0.1.0
    Finished release [optimized] target(s) in 3.41s
    Creating component target/wasm32-wasip2/release/acme_api.wasm
```

## 3. Write the manifest

Add a [`hyjal.toml`](/deploy/hyjal-toml) declaring the `api` Resource on the
Rust lane. Make it public so you can reach it directly.

```toml
[project]
name = "acme"

[resource.api]
lane = "rust"
public = true
```

The Rust lane runs `cargo component build` for you at deploy; you do not need to
commit the built artifact.

## 4. Deploy

```bash
$ hyjal deploy
Building resource api (lane: rust)...
  cargo component build --release ✓
Uploading artifact... digest sha256:a71e3d…09c4
Applying policy... ✓
Flipping route... ✓

Deployed acme/api
  https://api--acme.hyjal.cloud
```

## 5. Verify with curl

Call the endpoint:

```bash
$ curl https://api--acme.hyjal.cloud
{"service":"acme-api","ok":true}
```

Inspect the headers to confirm the status and content type:

```bash
$ curl -i https://api--acme.hyjal.cloud
HTTP/2 200
content-type: application/json

{"service":"acme-api","ok":true}
```

Each call ran on a fresh [Afterburner](/get-started/what-is-hyjal) instance,
metered and discarded. No state carries between requests.

## 6. Watch the requests

```bash
$ hyjal logs -f --resource api
[15:20:03] GET  /   200   2ms
[15:20:14] GET  /   200   1ms
```

## What you built

* A Rust `wasi:http` component that returns JSON.
* A public endpoint at `https://api--acme.hyjal.cloud` on the Rust lane.
* A working `curl` request served instance-per-request.

## Next steps

* Front the API with a web Resource: [Full-stack tutorial](/get-started/tutorials/full-stack-tutorial)
* Connect a database: [Connect Postgres](/get-started/tutorials/connect-postgres)
* Read the language reference: [Rust](/languages/rust)