Skip to content

Commit 2f0b85a

Browse files
committed
feat: add simple HTTP post request example
1 parent 6cced6b commit 2f0b85a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const std = @import("std");
2+
3+
const Client = std.http.Client;
4+
5+
pub fn main() !void {
6+
const allocator = std.heap.page_allocator;
7+
8+
var response: std.Io.Writer.Allocating = .init(allocator);
9+
defer response.deinit();
10+
11+
var client: Client = .{
12+
.allocator = allocator,
13+
};
14+
defer client.deinit();
15+
16+
_ = try client.fetch(.{
17+
.method = .POST,
18+
.location = .{
19+
.url = "https://echo.free.beeceptor.com",
20+
},
21+
.payload = "Hello World",
22+
.response_writer = &response.writer,
23+
});
24+
25+
const response_data = try response.toOwnedSlice();
26+
std.debug.print("{s}\n", .{response_data});
27+
}

0 commit comments

Comments
 (0)