Skip to content

golovatskygroup/lastpoint

Repository files navigation

LastPoint

HTTP/1.1 and HTTP/2 server framework for Pony.

Features

  • HTTP/1.1 - RFC 9112 compliant with keep-alive, chunked encoding, pipelining
  • HTTP/2 - RFC 7540 compliant (91/92 h2spec tests), multiplexing, flow control, HPACK compression
  • TLS + ALPN - Automatic protocol negotiation (h2 / http/1.1)
  • Router - Path parameters (:id), wildcards (*path), method-based routing
  • Middleware - CORS, logging, custom headers
  • Static files - Directory serving with path sanitization

Installation

Add LastPoint to your Pony project:

corral add github.com/golovatskygroup/lastpoint
corral fetch

Usage

use "lastpoint"

primitive HelloHandler is AppHandler
  fun apply(ctx: AppContext box): HTTPResponse =>
    HTTPResponse.ok("Hello " + ctx.param("name"))

actor Main
  new create(env: Env) =>
    let router: RequestRouter val = recover val
      let app1 = HttpApp.with_middleware(ServerHeaderMiddleware)
      let app2 = app1.get("/hello/:name", HelloHandler)
      app2.build()
    end
    HTTPServer(env, router, Logger(env), "0.0.0.0", "8080")

Building the Example

# Clone the repository
git clone https://github.com/golovatskygroup/lastpoint.git
cd lastpoint

# Fetch dependencies
corral fetch

# Build and run the example server
make build
./build/http_server

Router

let router: RequestRouter val = recover val
  let app1 = HttpApp
  let app2 = app1.get("/", IndexHandler)
  let app3 = app2.get("/users/:id", GetUserHandler)
  let app4 = app3.post("/users", CreateUserHandler)
  let app5 = app4.get("/assets/*path", StaticHandler)
  let app6 = app5.with_middleware(CORSMiddleware)
  app6.build()
end

Access parameters in handlers:

let user_id = ctx.param("id")      // path parameter
let query = ctx.query("search")    // query string
let body = ctx.body_json()         // parsed JSON body

Configuration

./http_server --host 0.0.0.0 --port 8443 --tls-enabled

Environment variables: HTTP_SERVER_HOST, HTTP_SERVER_PORT, HTTP_SERVER_TLS_ENABLED

Project Structure

lastpoint/
├── lastpoint/              # Library package
│   ├── http_app.pony       # Framework builder, AppContext, middleware chain
│   ├── flex_router.pony    # Router with path parameters and wildcards
│   ├── middleware.pony     # CORS, logging, server header middleware
│   ├── server.pony         # HTTPServer actor
│   ├── connection.pony     # HTTP/1.1 connection handler
│   ├── http2.pony          # HTTP/2 protocol implementation
│   ├── hpack.pony          # HPACK header compression (RFC 7541)
│   ├── tls.pony            # TLS/ALPN protocol negotiation
│   ├── request.pony        # HTTPRequest
│   ├── response.pony       # HTTPResponse
│   ├── logger.pony         # Structured logger
│   ├── config.pony         # Configuration loader
│   └── ...                 # Other modules
├── examples/
│   └── server/
│       ├── main.pony       # Example server entry point
│       └── handlers.pony   # Example request handlers
├── corral.json
├── Makefile
└── README.md

Requirements

  • Pony compiler 0.60+
  • OpenSSL 3.0+

On macOS with Homebrew: brew install openssl

Benchmarks

Performance comparison with Go (Apple Silicon M4 Max, macOS):

Throughput

Protocol Pony Go vs Go
HTTP/1.1 (wrk -t4 -c100 -d10s) 117,129 req/s 93,770 req/s 125%
HTTP/2 (h2load -n100000 -c50 -m100) 174,993 req/s 132,189 req/s 132%

Latency (HTTP/1.1, wrk -t4 -c100 -d10s)

Metric Pony Go
Avg 0.96 ms 1.05 ms
StdDev 1.59 ms 0.15 ms
Max 72.96 ms 3.73 ms

Latency (HTTP/2, h2load -n100000 -c50 -m100)

Metric Pony Go
Mean 23.52 ms 35.27 ms
StdDev 15.21 ms 90.84 ms

HPACK Compression

Metric Pony Go
Header space savings 95.36% 94.96%

Pony outperforms Go in both protocols: HTTP/1.1 by 25% and HTTP/2 by 32%. HTTP/1.1 latency is 9% lower than Go (0.96ms vs 1.05ms).

Key HTTP/1.1 optimizations: TCP_NODELAY, zero-allocation fast-path with pre-rendered responses, optimized request boundary scanning, pre-computed response sizes.

Test

# Start server
make run

# In another terminal
curl http://localhost:8080/ping    # PONG
curl http://localhost:8080/time    # Unix timestamp
curl http://localhost:8080/echo/hello  # hello

License

MIT

About

HTTP/1.1 and HTTP/2 server framework for Pony.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors