You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apple pie is a HTTP Server implementation in Zig. The initial goal is to offer full support for http versions 1.0 and 1.1 with 2.0 and further planned at a later stage. With Apple Pie I'd like to offer a library that contains all features you'd expect from a server, while still remaining performant. Rather than hiding complexity, I want to expose its functionality so users can replace and/or expand upon to fit their needs.
Roadmap
HTTP 1.1 spec (fully) implemented
Features
Crossplatform support
Extensive routing (see the router example) built in
Allows for both async and blocking I/O using Zig's std event loop
Example
A very basic implementation would be as follow:
conststd=@import("std");
consthttp=@import("apple_pie");
// use evented mode for event loop supportpubconstio_mode=.evented;
// optional root constant to define max stack buffer size per requestpubconstbuffer_size: usize=4096;
// optional root constant to define max header size per requestpubconstrequest_buffer_size: usize=4096;
/// Context variable, accessible by all handlers, allowing to access data objects/// without requiring them to be global. Thread-safety must be handled by the user.constContext=struct {
data: []constu8,
};
pubfnmain() !void {
vargpa=std.heap.GeneralPurposeAllocator(.{}){};
defer_=gpa.deinit();
constmy_context: Context= .{ .data="Hello, world!" };
tryhttp.listenAndServe(
gpa.allocator(),
trystd.net.Address.parseIp("127.0.0.1", 8080),
my_context,
index,
);
}
fnindex(ctx: Context, response: *http.Response, request: http.Request) !void {
_=request;
tryresponse.writer().print("{s}", .{ctx.data});
}
More examples can be found in the examples folder.
Building
Apple Pie is being developed on Zig's master branch and tries to keep up-to-date with its latest development.
To build Apple Pie a simple
zig build will suffice.