#Can you tell me how to send a request with json in the body of an http request in zig?
1 messages · Page 1 of 1 (latest)
hmhm
// Add content length header
var length_str: [32]u8 = undefined;
const length_str_len = std.fmt.formatIntBuf(length_str[0..], data.len, 10, .lower, .{});
try headers.append("content-length", length_str[0..length_str_len]);
try headers.append("content-type", "application/json");
// Perform the request
var req = try client.request(.POST, self.endpoint, headers, .{});
defer req.deinit();
try req.start();
_ = try req.write(data);
try req.wait();
where data is the json content
pub fn request(client: *Client, method: http.Method, uri: Uri, headers: http.Headers, options: RequestOptions) RequestError!Request {
```I thought I could set the body here in RequestOptions, is that wrong?
where did you see that? https://ziglang.org/documentation/master/std/#A;std:http.Client.RequestOptions has no such field
hmhm
start() checks for the existence of a "content-length" header and if it exists allows you to write to the body with write()