• This repository has been archived on 06/Nov/2023
  • Stars
    star
    347
  • Rank 117,961 (Top 3 %)
  • Language
    Zig
  • License
    MIT License
  • Created over 4 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Http server written in Zig

ZHP

status

A (work in progress) Http server written in Zig.

If you have suggestions on improving the design please feel free to comment!

Features

  • A zero-copy parser and aims to compete with these parser_benchmarks while still rejecting nonsense requests. It currently runs around ~1000MB/s.
  • Regex url routing thanks to ctregex
  • Struct based handlers where the method maps to the function name
  • A builtin static file handler, error page handler, and not found page handler
  • Middleware support
  • Parses forms encoded with multipart/form-data
  • Streaming responses
  • Websockets

See how it compares in the http benchmarks done by kprotty (now very old).

It's a work in progress... feel free to contribute!

Demo

Try out the demo at https://zhp.codelv.com.

Note: If you try to benchmark the server it'll ban you, please run it locally or on your own server to do benchmarks.

To make and deploy your own app see:

Example

See the example folder for a more detailed example.

const std = @import("std");
const web = @import("zhp");

pub const io_mode = .evented;
pub const log_level = .info;

const MainHandler = struct {
    pub fn get(self: *MainHandler, request: *web.Request, response: *web.Response) !void {
        _ = self;
        _ = request;
        try response.headers.put("Content-Type", "text/plain");
        _ = try response.stream.write("Hello, World!");
    }

};

pub const routes = [_]web.Route{
    web.Route.create("home", "/", MainHandler),
};

pub const middleware = [_]web.Middleware{
    web.Middleware.create(web.middleware.LoggingMiddleware),
};

pub fn main() anyerror!void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer std.debug.assert(!gpa.deinit());
    const allocator = gpa.allocator();

    var app = web.Application.init(allocator, .{.debug=true});
    defer app.deinit();

    try app.listen("127.0.0.1", 9000);
    try app.start();
}

More Repositories

1

zig-datetime

A date and time module for Zig
Zig
68
star
2

enamlx

Additional Qt Widgets for Enaml
Python
28
star
3

django-xadminlte

AdminLTE theme and plugins for django-xadmin
HTML
23
star
4

magicattr

A getattr and setattr that works on nested objects, lists, dicts, and any combination thereof without resorting to eval
Python
14
star
5

kivy-android-serial

Android serial port for Kivy
Python
13
star
6

pywinutils

Copy move and delete files using window's built in copy dialog (with progress window).
Python
12
star
7

arduino-json-rpc-server

JSON RPC Server for Arduino / Particle / Redbear Duo
C++
10
star
8

zq

A pure Zig database object relation mapper (currently using postgres)
Zig
9
star
9

zig-buildpack

A buildpack to deploy zig projects on Heroku / Dokku
Shell
7
star
10

smd-search

Demo enaml web app app to search for SMD components using pandas
Python
5
star
11

materialize

Materialize components for enaml-web
Python
5
star
12

zig-mimetypes

A mimetypes module for Zig
Zig
5
star
13

zig-kiwi

A cassowary constraint solver in zig
Zig
3
star
14

thermostat

Wifi thermostat with Arduino and enaml-native
C++
2
star
15

usb-scale

usb-scale
Zig
2
star
16

teensystep-simulator

Script to simulate multi-axis motion profiles for TeensyStep
Python
2
star
17

bible-app

Enaml-native bible app (outdated)
Python
1
star
18

pywavetrend

Python library for Wavetrend L-RX201 Active RFID readers
Python
1
star
19

cpp-rsa

Simple RSA script to encrypt/decrypt and generate keys using openssl
C++
1
star
20

enaml-hotswap

Live updates of enaml views while maintaining the runtime state
Python
1
star
21

enaml-kivy

Write kivy apps in Enaml
Python
1
star
22

pysoy-ping-pong

PySoy Ping Pong
C
1
star
23

zhp-demo

CSS
1
star