Zig
Zig
HttpPostJson2 Example
See more HTTP Examples
Demonstrates use of the HttpPostJson2 method.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code
// See PostJson2Async Example for the async equivalent of this example.
const http = try chilkat.Http.init();
defer http.deinit();
// Sends a POST equivalent to the following CURL command:
// curl -X POST https://sandbox.plaid.com/institutions/get \
// -H 'content-type: application/json' \
// -d '{
// "client_id": String,
// "secret":String,
// "count": Number,
// "offset": Number
// }'
// Suppress some default headers that would automatically added..
ERROR: Property not in the Zig package: Http.AcceptCharset
http.ERROR("");
http.setUserAgent("");
ERROR: Property not in the Zig package: Http.AcceptLanguage
http.ERROR("");
http.setAllowGzip(false);
_ = "{\"client_id\": \"PLAID_CLIENT_ID\", \"secret\":\"PLAID_SECRET\", \"count\": 10, \"offset\": 0}";
ERROR: Method not in the Zig package: Http.PostJson2
ERROR: Method not in the Zig package: Http.PostJson2
const resp = http.ERROR();
if (!http.getLastMethodSuccess()) {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
}
const status_code = resp.getStatusCode();
std.debug.print("Response status code = {d}\n", .{status_code});
// Examine the JSON response..
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.load(try resp.getBodyStr(alloc)) catch {};
json.setEmitCompact(false);
std.debug.print("JSON Response Body:\n", .{});
std.debug.print("{s}\n", .{try json.emit(alloc)});
}