this is my code
const url = try std.fmt.allocPrint(alloc, "{s}/register", .{LOCALHOST});
defer alloc.free(url);
var client = http.Client{
.allocator = alloc,
};
defer client.deinit();
var body = std.ArrayList(u8).init(alloc);
errdefer body.deinit();
var result: http.Client.FetchResult = undefined;
if (method == .GET) {
result = try client.fetch(.{
.location = .{ .url = url },
.method = method,
.extra_headers = &.{
.{ .name = "content-type", .value = "application/json" },
},
.response_storage = .{ .dynamic = &body },
});
} else {
var string = std.ArrayList(u8).init(alloc);
defer string.deinit();
try std.json.stringify(userCreds, .{}, string.writer());
result = try client.fetch(.{
.location = .{ .url = url },
.method = method,
.payload = string.items,
.extra_headers = &.{
.{ .name = "content-type", .value = "application/json" },
},
.response_storage = .{ .dynamic = &body },
});
}
return receivedResult{
.status = result.status,
.body = try body.toOwnedSlice(),
};
}```