faucet-source-xml
A config-driven XML/SOAP API source with automatic XML-to-JSON conversion, dot-path record extraction, and pluggable authentication.
Part of the faucet-stream ecosystem.
Installation
[]
= "0.1"
= { = "1", = ["full"] }
Or via the umbrella crate:
= { = "0.2", = ["source-xml"] }
Quick Start
use ;
async
Configuration
XmlStreamConfig
| Field | Type | Default | Description |
|---|---|---|---|
base_url |
String |
(required) | Base URL of the API |
path |
String |
(required) | Request path appended to base_url |
method |
Method |
GET |
HTTP method (GET or POST for SOAP) |
auth |
XmlAuth |
XmlAuth::None |
Authentication method |
headers |
HeaderMap |
empty | Additional request headers |
body |
Option<String> |
None |
Optional request body (e.g. SOAP envelope as raw XML string) |
records_element_path |
Option<String> |
None |
Dot-separated path to the repeating element in the XML response (e.g. "Envelope.Body.GetUsersResponse.Users.User") |
pagination |
Option<XmlPagination> |
None |
Pagination configuration |
max_pages |
Option<usize> |
None |
Maximum number of pages to fetch |
query_params |
HashMap<String, String> |
empty | Query parameters to include in every request |
Authentication (XmlAuth)
| Variant | Fields | Description |
|---|---|---|
None |
-- | No authentication |
Bearer(String) |
token | Bearer token in the Authorization header |
Basic { username, password } |
String, String |
HTTP Basic authentication |
Custom(HeaderMap) |
headers | Custom headers (e.g. SOAP action headers, API keys). Not serializable |
Pagination (XmlPagination)
| Variant | Fields | Stops When |
|---|---|---|
PageNumber |
param_name, start_page, page_size (optional), page_size_param (optional) |
Response returns zero records, or fewer records than page_size |
Offset |
offset_param, limit_param, limit |
Fewer records returned than limit, or loop detected |
Config Loading
use ;
use XmlStreamConfig;
let config: XmlStreamConfig = load_json?;
let config: XmlStreamConfig = load_env_file?;
Example JSON config
Example .env file
XML_BASE_URL=https://api.example.com
XML_PATH=/users.xml
XML_METHOD=GET
XML_MAX_PAGES=50
Config Schema Introspection
use Source;
let stream = new;
let schema = stream.config_schema;
println!;
Examples
REST XML API with page-number pagination
use ;
let config = new
.records_element_path
.pagination
.max_pages;
let stream = new;
let products = stream.fetch_all.await?;
println!;
SOAP API with custom headers
use ;
use Method;
let config = new
.method
.auth
.body
.records_element_path;
let stream = new;
let orders = stream.fetch_all.await?;
Offset-paginated XML feed
use ;
let config = new
.records_element_path
.pagination
.query_param;
let stream = new;
let articles = stream.fetch_all.await?;
License
Licensed under MIT or Apache-2.0.