Skip to main content

The Prism Server

PrismHTTPServer is a Swift actor built on Apple’s Network.framework. It handles TCP connections, HTTP parsing, routing, and middleware — all without a single third-party dependency.
Because PrismHTTPServer is an actor, every interaction is concurrency-safe by default. You never need to worry about data races when registering routes or adding middleware.

Creating a Server

main.swift
That’s it. Five lines to a running HTTP server.

Configuration

Prism supports TLS natively via Network.framework — no OpenSSL needed.

Registering Routes

Register routes using the HTTP method helpers:
Route Registration

Adding Middleware

Middleware runs on every request, in the order you add it:
Middleware Stack
Middleware order matters. Put error handling and logging at the top so they wrap everything else.

Route Groups

Group related routes under a shared prefix with optional group-specific middleware:
Route Groups

Server Lifecycle

Start and Stop
For production, pair with PrismGracefulShutdown to drain connections before stopping:
Graceful Shutdown

Full Example

Here’s a complete server with routing, middleware, database, and error handling:
Complete Server

Routing

Learn about path parameters, wildcards, and route groups.

Middleware

Build custom middleware and understand the execution chain.