Expand description
§indexnow-api
Async IndexNow client for Rust.
IndexNow is an open protocol that lets a website tell search engines the moment a URL is added, updated or deleted, instead of waiting for the next crawl. One request reaches every participating engine: Microsoft Bing, Yandex, Naver, Seznam.cz and Yep. (Google does not support IndexNow.)
This crate wraps the POST /IndexNow JSON endpoint with a small
reqwest-based client. There is no other runtime dependency; bring your
own async runtime such as Tokio.
§Quick start
use indexnow_api::IndexNowApi;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// `host` is your site's hostname, `key` is your IndexNow key
// (the same string you host at https://<host>/<key>.txt).
let api = IndexNowApi::new("www.example.com", "7be9fca90b3b4b039983fa8f06e03ee8");
// Up to 10,000 URLs per request. Anything that implements `ToString` works.
api.send_urls(vec![
"https://www.example.com/new-page",
"https://www.example.com/updated-article",
])
.await?;
Ok(())
}§Choosing a search engine endpoint
By default requests go to https://api.indexnow.org, which forwards the
submission to all IndexNow engines. Use IndexNowApi::set_search_engine
to target one engine directly; pass the origin only, the /IndexNow path
is appended by the crate.
use indexnow_api::IndexNowApi;
let mut api = IndexNowApi::new("www.example.com", "7be9fca90b3b4b039983fa8f06e03ee8");
api.set_search_engine("https://www.bing.com");
api.set_key_location("https://www.example.com/keys/7be9fca90b3b4b039983fa8f06e03ee8.txt");
api.send_urls(vec!["https://www.example.com/"]).await?;§Errors
send_urls returns IndexNowError when the
request cannot be sent (IndexNowError::Connection) or the endpoint
answers with a status other than 200 or 202 (IndexNowError::Status,
carrying the code and the response body). The error implements
std::error::Error and std::fmt::Display.
Structs§
- Index
NowApi - IndexNow client bound to one website (
host) and one IndexNow key. - Send
Data - JSON body of an IndexNow submission
(
{"host": ..., "key": ..., "keyLocation": ..., "urlList": [...]}).
Enums§
- Index
NowError - Error returned by
IndexNowApi::send_urls.
Type Aliases§
- Google
ApiError Deprecated - Former name of
IndexNowError, kept so 1.0 code keeps compiling.