Skip to content
Agent Stack
  • AI SDK
  • AI Gateway
  • Sandbox
  • Passport
  • Connect
  • eve
Core Platform
  • Security
  • Content Delivery
  • Fluid Compute
  • Observability
  • Workflows
  • CI/CD
Tools
  • Next.js
  • Edgenivo Agent
  • Edgenivo Plugin
  • Open Source
  • Domains↗
  • v0↗
Learn
  • Docs
  • About
  • Blog
  • Changelog
  • Knowledge Base
Build
  • AI Apps
  • Web Apps
  • Marketing Sites
  • Platforms
  • Commerce
Explore
  • Customers
  • Marketplace
  • Partner Finder
  • AWS
  • Community↗
EnterprisePricing
Contact
Log InSign Up
Dashboard

Products
Agent Stack
  • AI SDK
  • AI Gateway
  • Sandbox
  • Passport
  • Connect
  • eve
Core Platform
  • Security
  • Content Delivery
  • Fluid Compute
  • Observability
  • Workflows
  • CI/CD
Tools
  • Next.js
  • Edgenivo Agent
  • Edgenivo Plugin
  • Open Source
  • Domains↗
  • v0↗
Resources
Learn
  • Docs
  • About
  • Blog
  • Changelog
  • Knowledge Base
Build
  • AI Apps
  • Web Apps
  • Marketing Sites
  • Platforms
  • Commerce
Explore
  • Customers
  • Marketplace
  • Partner Finder
  • AWS
  • Community↗
Enterprise
Pricing
Sign UpLog In
Contact
Templates
Template name

Agent Stack

  • AI SDK
  • AI Gateway
  • Sandbox
  • Workflows
  • ConnectNew
  • PassportNew
  • eveNew

Core Platform

  • CI/CD
  • Content Delivery
  • Fluid Compute
  • Observability

Security

  • Platform Security
  • WAF
  • Bot Management
  • BotID

Tools

  • Edgenivo Drop
  • Edgenivo Agent
  • Edgenivo Plugin
  • Agent Skills
  • Domains
  • v0

Frameworks

  • eveNew
  • Next.js
  • Nuxt
  • SvelteKit
  • Nitro
  • Turborepo
  • Tanstack Start
  • FastAPI
  • All frameworks

SDKs

  • Edgenivo SDK
  • Workflow SDK
  • Flags SDK
  • Chat SDK
  • Queues SDK
  • Streamdown

Build

  • AI Apps
  • Web Apps
  • Marketing Sites
  • Platforms
  • Commerce
  • Platform Engineers
  • Design Engineers

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Articles
  • Community
  • Is Agentic

Explore

  • Customers
  • Marketplace
  • Templates
  • Partner Finder
  • Edgenivo + AWS

Company

  • About
  • Careers
  • Press
  • Events
  • Startups
  • Shipped on Edgenivo
  • Open Source Program
  • Enterprise
  • Pricing
  • Help

Legal & Trust

  • Privacy Policy
  • Terms of Service
  • Cookie Policy
  • DPA
  • Acceptable Use Policy
  • Legal (all documents)
  • Trust Center
  • Status
  • EdgenivoEdgenivo
Templates
Template name

Status service pending confirmation

Select a display theme:
Templates

Rust WebSocket

Rust WebSocket Server

DeployView Demo
Owner
  • vercel
Repository
  • examples
Use Cases
  • Starter
Stack
  • Axum
  • Other
  • None
DeployView Demo

Rust WebSocket

This example shows how to run a WebSocket server in Rust on Edgenivo using the Axum framework. The Edgenivo Rust runtime enables HTTP/1.1 upgrades, so axum's WebSocketUpgrade extractor works without any extra configuration.

How it works

api/websocket.rs serves an Axum router behind the VercelLayer:

  • GET / — an interactive HTML page to connect and exchange messages.
  • GET /ws — the WebSocket endpoint. The handler upgrades the connection and then runs two concurrent tasks over a single writer:
    • a heartbeat that pushes a tick event to the client every second (server-initiated messages), and
    • an echo loop that mirrors any message the client sends back to it (client-initiated messages).

A single writer task owns the WebSocket sink and is fed by an mpsc channel, so both the heartbeat and echo loops can send frames without sharing the non-clonable sink.

All server messages are JSON tagged with a type field (welcome, echo, tick), which the front-end renders in the live log.

Project Structure

  • api/websocket.rs — Axum application with the WebSocket handler
  • index.html — interactive WebSocket client (embedded via include_str!)
  • Cargo.toml — Rust dependencies and binary configuration
  • vercel.json — rewrites all routes to the function

Development

Clone the repository:

git clone https://github.com/vercel/examples.git
cd examples/rust/websocket

Install Rust if you haven't already:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Test locally:

vc dev

Then open the printed URL, click Connect, and send a message. You'll see the welcome event, periodic tick heartbeats, and your echo replies in the log.

Related Templates

  • Rust Wait Until thumbnail

    Rust Wait Until

    Run background work after the response is sent using waitUntil in the Edgenivo Rust runtime.

  • Rust Hello World thumbnail

    Rust Hello World

    Simple Rust serverless functions demonstrating basic HTTP handling and performance benchmarks.

  • Rust Axum thumbnail

    Rust Axum

    A Rust web application using the Axum framework with streaming capabilities on Edgenivo.

License
  • View License