Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crispy-strawberry/http.zig
An HTTP/1.1 compliant client and server in Zig
https://github.com/crispy-strawberry/http.zig
http tcp zig ziglang
Last synced: 4 days ago
JSON representation
An HTTP/1.1 compliant client and server in Zig
- Host: GitHub
- URL: https://github.com/crispy-strawberry/http.zig
- Owner: crispy-strawberry
- License: apache-2.0
- Created: 2023-12-21T11:10:12.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-24T19:27:43.000Z (about 1 year ago)
- Last Synced: 2024-11-18T07:00:47.900Z (2 months ago)
- Topics: http, tcp, zig, ziglang
- Language: Zig
- Homepage: https://codeberg.org/crispy-strawberry/http.zig
- Size: 49.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# http.zig
Creating an HTTP/1.1 compliant server in Zig.# Using
Let's look at how to use the `http` package in your own project.+ Run the following command inside your project root -
```
zig fetch git+https://github.com/crispy-strawberry/http.zig#main --save=http
```
+ Open `build.zig` add the following lines -
```zig
const http = b.dependency("http", .{
.target = target,
.optimize = optimize,
});exe.addModule("http", http.module("http"));
```
+ Enjoy!
```zig
const std = @import("std");
const http = @import("http");const Server = http.Server;
pub fn main() !void {
var server = Server.init(allocator, .{
.reuse_port = true,
});
defer server.deinit();try server.listen(std.net.Address.initIp4([_]u8{ 127, 0, 0, 1 }, 8000));
while (true) {
try server.accept();
}
}
```## Options provided by the library
The library provides two options to change the default settings.
1. Firstly, it provides `REQ_SIZE` to choose the max size of the request stored
on the stack. Default is 4kb.
2. It also provides an option to choose the max size in bytes of the HTTP
method. For example, `GET` is 3 bytes and `POST` is 4 bytes. The default
maximum size for methods is 24 bytes.To change these, you can do -
```zig
const http = b.dependency("http", .{
.target = target,
.optimize = optimize,
.REQ_SIZE = @as(usize, 2048),
.MAX_METHOD_SIZE = @as(u16, 32),
});
```# License
The library is dual licensed under `MPL-2.0` or `APACHE-2.0`.
Choose at your own discretion.# Contributing
Please make pull requests to https://codeberg.org/crispy-strawberry/http.zig