Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/darrensemusemu/httpz

A simple Go like http server implementation
https://github.com/darrensemusemu/httpz

http http-server zig

Last synced: 27 days ago
JSON representation

A simple Go like http server implementation

Awesome Lists containing this project

README

        

# httpz

A simple Go like http server implementation. Note: WIP.

## Example

### Simple Server

```zig
// ....
const addr = try net.Address.parseIp("0.0.0.0", 8080);
var http_server = httpz.Server.init(allocator, addr);
defer http_server.close();

const t = struct {
fn handleHome(res: *httpz.Response, _: *httpz.Request) anyerror!void {
res.status = .ok;
try res.setHeader("Content-Type", "text/plain");
try res.body.appendSlice("Hello World");
}
};

var mux = httpz.Mux.init(allocator);
try mux.handle("/", t.handleHome);

std.log.info("running on port: 8080", .{});
try http_server.listenAndServe(&mux);
```