Running a Server

In this guide, we'll walk you through the process of running a server on your EdgeOS device. We'll be using the Hummingbird, a popular and lightweight Swift web server framework to run on your EdgeOS device. There are many times you want to communicate with your EdgeOS device over traditional web protocols like HTTP, and Hummingbird is a great way to do that.

Step 1: Create a new project

macOS

mkdir HummingBirdServerExample  
cd HummingBirdServerExample
edge init

Now your favorite editor (we highly recommend VSCode, Cursor, or Windsurf with the Edge VSCode Extension) and open the project.

Step 2: Open the project in your favorite editor

macOS

code . 
# or 
cursor .
# or
windsurf .

Step 3. Add the Hummingbird package

Open up Package.swift and add the following dependencies:

Package.swift

platforms: [
  .macOS(.v15), // a requirement for compiling Hummingbird on macOS
],
dependencies: [
  .package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.15.0"),
],
targets: [
  .target(
    name: "HummingBirdServerExample",
    dependencies: [
      .product(name: "Hummingbird", package: "hummingbird"),
    ],
  ),
],

Step 4. Open the main.swift file

The edge init command will create a main.swift file for you. Open it in your favorite editor you should see the following code:

main.swift

import Hummingbird

// Create a router and add a simple route
let router = Router()
router.get("/") { request, context in
    "Hello, World!"
}
// Create and configure the application
let app = Application(
    router: router,
    configuration: .init(address: .hostname("0.0.0.0", port: 9080))
)

// Run the server
try await app.run()

Step 5. Run the server on your EdgeOS device

First make sure your EdgeOS device is set as your active device. Open up your VSCode Edge Extension and look for your the "DEVICES" panel, and click on the EdgeOS device to make the active one.

Active Device

EdgeOS

edge run

Next debug and run your server on your EdgeOS device.

Debug Run

Step 6. Test your server

While on your Macbook. Open up your browser and navigate to http://edgeos-device.local:9080. You should see the following output:

Web Browser

Congratulations!

You've successfully run a server on your EdgeOS device. You can now start building your own server applications. So long as your device is on the same network as your Macbook, you can access your server locally! You've now made a full fledge edge computing web server accessible outside of a data center!

Was this page helpful?