https://github.com/klaussilveira/iab-rust
Provides idiomatic Rust data structures for IAB OpenRTB, AdCOM and other specs.
https://github.com/klaussilveira/iab-rust
adcom iab openrtb rtb
Last synced: 4 months ago
JSON representation
Provides idiomatic Rust data structures for IAB OpenRTB, AdCOM and other specs.
- Host: GitHub
- URL: https://github.com/klaussilveira/iab-rust
- Owner: klaussilveira
- License: mit
- Created: 2025-05-05T18:13:30.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-05T18:50:20.000Z (about 1 year ago)
- Last Synced: 2025-06-06T01:04:11.099Z (about 1 year ago)
- Topics: adcom, iab, openrtb, rtb
- Language: Rust
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# IAB Rust
This library provides strongly-typed structures for OpenRTB, AdCOM, and other specifications published by the Interactive Advertising Bureau (IAB) for the Rust programming language.
The primary goal is to define these types in an idiomatic Rust way, adhering strictly to the official specifications. This allows for easier integration and validation of OpenRTB-based protocols within Rust applications.
## Complete
- [OpenRTB 2.6](https://github.com/InteractiveAdvertisingBureau/openrtb2.x/blob/main/2.6.md)
- [AdCOM 1.0](https://github.com/InteractiveAdvertisingBureau/AdCOM/blob/main/AdCOM%20v1.0%20FINAL.md)
## Roadmap
The following specifications are planned for future implementation:
- [OpenRTB Dynamic Native Ads 1.2](https://github.com/InteractiveAdvertisingBureau/Native-Ads/blob/main/OpenRTB-Native-Ads-Specification-Final-1.2.md)
## Creating a Bid Request
Below is an example of creating a bid request:
```rust
use iab::openrtb2::*;
use serde_json;
let request = BidRequest {
id: "80ce30c53c16e6ede735f123ef6e32361bfc7b22".to_string(),
at: Some(1),
cur: Some(vec!["USD".to_string()]),
imp: vec![Imp {
id: "1".to_string(),
bidfloor: Some(0.03),
banner: Some(Banner {
h: Some(250),
w: Some(300),
pos: Some(0),
..Default::default()
}),
..Default::default()
}],
site: Some(Site {
id: Some("102855".to_string()),
cat: Some(vec!["IAB3-1".to_string()]),
domain: Some("www.foobar.com".to_string()),
page: Some("http://www.foobar.com/1234.html".to_string()),
publisher: Some(Publisher {
id: Some("8953".to_string()),
name: Some("foobar.com".to_string()),
cat: Some(vec!["IAB3-1".to_string()]),
domain: Some("foobar.com".to_string()),
..Default::default()
}),
..Default::default()
}),
user: Some(User {
id: Some("55816b39711f9b5acf3b90e313ed29e51665623f".to_string()),
..Default::default()
}),
..Default::default()
};
let output = serde_json::to_string_pretty(&request).expect("Failed to serialize BidRequest");
```
## Parsing a Bid Request
Below is an example of parsing a bid request:
```rust
use iab::openrtb2::*;
use serde_json::{Result};
let data = r#"
{
"id": "80ce30c53c16e6ede735f123ef6e32361bfc7b22",
"at": 1,
"cur": ["USD"],
"imp": [
{ "id": "1", "bidfloor": 0.03, "banner": {"h": 250, "w": 300, "pos": 0} }
],
"site": {
"id": "102855",
"cat": ["IAB3-1"],
"domain": "www.foobar.com",
"page": "http://www.foobar.com/1234.html",
"publisher": {
"id": "8953",
"name": "foobar.com",
"cat": ["IAB3-1"],
"domain": "foobar.com"
}
},
"user": {"id": "55816b39711f9b5acf3b90e313ed29e51665623f"}
}"#;
// Parse the Bid Request JSON
let br: BidRequest = serde_json::from_str(data).unwrap();
// Do things just like with any other Rust data structure
println!(
"Bid Request {}, with impression {} on {:?}",
br.id,
br.imp[0].id,
br.site.unwrap().domain
);
```
## Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.