Zig
Zig
Magyar Nemzeti Bank (MNB) Get Currencies
See more REST Misc Examples
The Magyar Nemzeti Bank (MNB) is the central bank of Hungary. In this role, its primary objective is to achieve and maintain price stability. The MNB website is available to visitors in both Hungarian and English. The MNB provides the Arfolyam (trans. Exchange Rate) API, which can be used to retrieve current and historic currency exchange rates. This service uses SOAP calls issued in XML format.This example gets a list of currencies.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const rest = try chilkat.Rest.init();
defer rest.deinit();
// URL: http://www.mnb.hu/arfolyamok.asmx
const b_tls = false;
const port = 80;
const b_auto_reconnect = true;
rest.connect("www.mnb.hu", port, b_tls, b_auto_reconnect) catch {
std.debug.print("ConnectFailReason: {d}\n", .{rest.getConnectFailReason()});
std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
return;
};
// --------------------------------------------------------------------------------
// Also see Chilkat's Online WSDL Code Generator
// to generate code and SOAP Request and Response XML for each operation in a WSDL.
// --------------------------------------------------------------------------------
const xml = try chilkat.Xml.init();
defer xml.deinit();
xml.setTag("soapenv:Envelope");
xml.addAttribute("xmlns:soapenv", "http://schemas.xmlsoap.org/soap/envelope/") catch {};
xml.addAttribute("xmlns:web", "http://www.mnb.hu/webservices/") catch {};
xml.updateChildContent("soapenv:Header", "");
xml.updateChildContent("soapenv:Body|web:GetCurrencies", "");
rest.addHeader("Content-Type", "text/xml") catch {};
rest.addHeader("SOAPAction", "/webservices/MNBArfolyamServiceSoap/GetCurrencies") catch {};
rest.addHeader("Accept", "application/xml") catch {};
const sb_request_body = try chilkat.StringBuilder.init();
defer sb_request_body.deinit();
xml.getXmlSb(sb_request_body) catch {};
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
rest.fullRequestSb("POST", "/arfolyamok.asmx", sb_request_body, sb_response_body) catch {
std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
return;
};
const resp_status_code = rest.getResponseStatusCode();
if (resp_status_code >= 400) {
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try rest.getResponseHeader(alloc)});
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try sb_response_body.getAsString(alloc)});
return;
}
std.debug.print("response status code = {d}\n", .{resp_status_code});
const xml_response = try chilkat.Xml.init();
defer xml_response.deinit();
xml_response.loadSb(sb_response_body, true) catch {};
std.debug.print("{s}\n", .{try xml_response.getXml(alloc)});
// The XML response contains this:
// <?xml version="1.0" encoding="utf-8" ?>
// <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
// <s:Body>
// <GetCurrenciesResponse xmlns="http://www.mnb.hu/webservices/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
// <GetCurrenciesResult><MNBCurrencies><Currencies><Curr>HUF</Curr><Curr>EUR</Curr><Curr>AUD</Curr> ... </MNBCurrencies></GetCurrenciesResult>
// </GetCurrenciesResponse>
// </s:Body>
// </s:Envelope>
// Get the GetCurrenciesResult
const result_encoded = try xml_response.getChildContent(alloc, "s:Body|GetCurrenciesResponse|GetCurrenciesResult");
std.debug.print("{s}\n", .{result_encoded});
// Entity decode the result to get XML.
const sb_result = try chilkat.StringBuilder.init();
defer sb_result.deinit();
sb_result.append(result_encoded) catch {};
sb_result.entityDecode() catch {};
// Load it into XML.
const xml_result = try chilkat.Xml.init();
defer xml_result.deinit();
xml_result.loadSb(sb_result, true) catch {};
std.debug.print("{s}\n", .{try xml_result.getXml(alloc)});
// The result is this:
// <?xml version="1.0" encoding="utf-8" ?>
// <MNBCurrencies>
// <Currencies>
// <Curr>HUF</Curr>
// <Curr>EUR</Curr>
// <Curr>AUD</Curr>
// <Curr>BGN</Curr>
// <Curr>BRL</Curr>
// <Curr>CAD</Curr>
// <Curr>CHF</Curr>
// <Curr>CNY</Curr>
// <Curr>CZK</Curr>
// <Curr>DKK</Curr>
// <Curr>GBP</Curr>
// <Curr>HKD</Curr>
// <Curr>HRK</Curr>
// <Curr>IDR</Curr>
// <Curr>ILS</Curr>
// <Curr>INR</Curr>
// <Curr>ISK</Curr>
// <Curr>JPY</Curr>
// <Curr>KRW</Curr>
// <Curr>MXN</Curr>
// <Curr>MYR</Curr>
// <Curr>NOK</Curr>
// <Curr>NZD</Curr>
// <Curr>PHP</Curr>
// <Curr>PLN</Curr>
// <Curr>RON</Curr>
// <Curr>RSD</Curr>
// <Curr>RUB</Curr>
// <Curr>SEK</Curr>
// <Curr>SGD</Curr>
// <Curr>THB</Curr>
// <Curr>TRY</Curr>
// <Curr>UAH</Curr>
// <Curr>USD</Curr>
// <Curr>ZAR</Curr>
// <Curr>ATS</Curr>
// <Curr>AUP</Curr>
// <Curr>BEF</Curr>
// <Curr>BGL</Curr>
// <Curr>CYN</Curr>
// <Curr>CSD</Curr>
// <Curr>CSK</Curr>
// <Curr>DDM</Curr>
// <Curr>DEM</Curr>
// <Curr>EEK</Curr>
// <Curr>EGP</Curr>
// <Curr>ESP</Curr>
// <Curr>FIM</Curr>
// <Curr>FRF</Curr>
// <Curr>GHP</Curr>
// <Curr>GRD</Curr>
// <Curr>IEP</Curr>
// <Curr>ITL</Curr>
// <Curr>KPW</Curr>
// <Curr>KWD</Curr>
// <Curr>LBP</Curr>
// <Curr>LTL</Curr>
// <Curr>LUF</Curr>
// <Curr>LVL</Curr>
// <Curr>MNT</Curr>
// <Curr>NLG</Curr>
// <Curr>OAL</Curr>
// <Curr>OBL</Curr>
// <Curr>OFR</Curr>
// <Curr>ORB</Curr>
// <Curr>PKR</Curr>
// <Curr>PTE</Curr>
// <Curr>ROL</Curr>
// <Curr>SDP</Curr>
// <Curr>SIT</Curr>
// <Curr>SKK</Curr>
// <Curr>SUR</Curr>
// <Curr>VND</Curr>
// <Curr>XEU</Curr>
// <Curr>XTR</Curr>
// <Curr>YUD</Curr>
// </Currencies>
// </MNBCurrencies>
//
}