Skip to content

Commit 2e52b11

Browse files
committed
feat: add simple HTTP post request example
1 parent e4327da commit 2e52b11

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/examples/networking/http-client.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn main() !void {
1717
.extra_headers = &.{
1818
.{
1919
.name = "cookie",
20-
.value = "***REMOVED***",
20+
.value = "session=53616c7465645f5f51bb2753ea90c02364db584f31a2b53d145fd73852e0eab2df9622cfc4298efcbadb42cb1561c5c04aea2197808df1573cd9bd6f39f0a564",
2121
},
2222
},
2323
.method = .GET,
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+
}

src/examples/networking/http-to-file.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn main() !void {
1818
.extra_headers = &.{
1919
.{
2020
.name = "cookie",
21-
.value = "***REMOVED***",
21+
.value = "session=53616c7465645f5f51bb2753ea90c02364db584f31a2b53d145fd73852e0eab2df9622cfc4298efcbadb42cb1561c5c04aea2197808df1573cd9bd6f39f0a564",
2222
},
2323
},
2424
.method = .GET,

0 commit comments

Comments
 (0)