| Crates.io | indexnow-api |
| lib.rs | indexnow-api |
| version | 1.0.0 |
| created_at | 2025-09-01 23:39:57.951507+00 |
| updated_at | 2025-09-02 05:26:00.588186+00 |
| description | IndexNow API |
| homepage | |
| repository | https://github.com/uiuifree/rust-indexnow-api |
| max_upload_size | |
| id | 1820341 |
| size | 55,895 |
A Rust library for instantly notifying search engines about URL changes using the IndexNow protocol. Supports Bing, Yandex, and other IndexNow-compatible search engines.
Add this to your Cargo.toml:
[dependencies]
indexnow-api = "0.1.0"
tokio = { version = "1", features = ["full"] }
use indexnow_api::IndexNowApi;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize with your domain and API key
let api = IndexNowApi::new(
"www.example.com",
"7be9fca90b3b4b039983fa8f06e03ee8"
);
// Notify search engines about URL changes
let urls = vec!["https://www.example.com/new-page".to_string()];
api.send_urls(urls).await?;
println!("URLs successfully submitted to IndexNow!");
Ok(())
}
Submit multiple URLs at once for better efficiency:
use indexnow_api::IndexNowApi;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api = IndexNowApi::new(
"www.example.com",
"7be9fca90b3b4b039983fa8f06e03ee8"
);
// Submit up to 10,000 URLs per request
let urls = vec![
"https://www.example.com/page1".to_string(),
"https://www.example.com/page2".to_string(),
"https://www.example.com/updated-article".to_string(),
];
api.send_urls(urls).await?;
Ok(())
}
Target specific search engines by setting custom endpoints:
use indexnow_api::IndexNowApi;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut api = IndexNowApi::new(
"www.example.com",
"7be9fca90b3b4b039983fa8f06e03ee8"
);
// Use Bing's dedicated endpoint for faster processing
api.set_search_engine("https://www.bing.com");
// Optional: specify custom key file location
api.set_key_location("https://www.example.com/my-indexnow-key.txt");
let urls = vec!["https://www.example.com/important-update".to_string()];
api.send_urls(urls).await?;
Ok(())
}
Handle different types of errors gracefully:
use indexnow_api::{IndexNowApi, GoogleApiError};
#[tokio::main]
async fn main() {
let api = IndexNowApi::new("www.example.com", "your-api-key");
let urls = vec!["https://www.example.com/page".to_string()];
match api.send_urls(urls).await {
Ok(()) => println!("✅ URLs successfully submitted"),
Err(GoogleApiError::Connection(msg)) => {
eprintln!("🔗 Connection error: {}", msg);
}
Err(GoogleApiError::Status(code)) => {
eprintln!("⚠️ HTTP error with status: {}", code);
}
}
}
IndexNowApiThe main struct for interacting with IndexNow APIs.
pub fn new<T: ToString, U: ToString>(host: T, key: U) -> IndexNowApi
Parameters:
host - Your website's hostname (e.g., "www.example.com")key - Your IndexNow API key (32-character hexadecimal string)set_search_enginepub fn set_search_engine<T: ToString>(&mut self, search_engine: T)
Sets a custom search engine endpoint. Default: https://api.indexnow.org
Popular endpoints:
https://www.bing.comhttps://yandex.comset_key_locationpub fn set_key_location<T: ToString>(&mut self, key_location: T)
Specifies where your API key file is hosted (optional).
send_urlspub async fn send_urls(&self, urls: Vec<String>) -> Result<(), GoogleApiError>
Submits a list of URLs to the search engine for indexing.
Limits:
hostCreate a 32-character hexadecimal key:
# Using OpenSSL
openssl rand -hex 16
# Using Python
python -c "import secrets; print(secrets.token_hex(16))"
# Example output: 7be9fca90b3b4b039983fa8f06e03ee8
Create a text file containing only your API key and host it at:
https://yourdomain.com/[your-api-key].txt
Example:
7be9fca90b3b4b039983fa8f06e03ee8https://www.example.com/7be9fca90b3b4b039983fa8f06e03ee8.txt7be9fca90b3b4b039983fa8f06e03ee8Test your setup by submitting a URL and checking for successful responses.
| Search Engine | Endpoint | Status |
|---|---|---|
| Bing | https://www.bing.com/indexnow |
✅ Supported |
| Yandex | https://yandex.com/indexnow |
✅ Supported |
| Generic | https://api.indexnow.org/indexnow |
✅ Supported |
GoogleApiError::Connection(String)Network connectivity issues, DNS problems, or server timeouts.
GoogleApiError::Status(u8)HTTP status codes indicating API errors (4xx, 5xx responses).
Check out the tests/ directory for more usage examples:
cargo test -- --nocapture
We welcome contributions! Please feel free to submit issues, feature requests, or pull requests.
git clone https://github.com/uiuifree/rust-indexnow-api.git
cd rust-indexnow-api
cargo test
git checkout -b feature/amazing-feature)cargo test passesgit commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Questions? Open an issue on GitHub or check the documentation.