2 releases

0.1.1 Sep 18, 2022
0.1.0 Sep 17, 2022

#140 in #api-wrapper

MIT license

10KB
74 lines

ntfy-api

This library contains async rust bindings for the ntfy API. It uses reqwest as HTTP client.

Features implemented:

  • Publish as JSON
  • Post directly to topic
  • File attachments
  • Websockets

Usage

Cargo.toml:

[dependencies]
tokio = { version = "1", features = ["full"] }
ntfy-api = "^0.1.1"
use ntfy_api::{NtfyApi, NtfyMsg};

#[tokio::main]
async fn main() {
   let api = NtfyApi::default();
   let ntfy_msg = NtfyMsg {
       topic: String::from("alerts"),
       message: Some(String::from("Message body")),
       title: Some(String::from("New Message")),
       tags: None,
       priority: None,
       attach: None,
       filename: None,
       click: None,
       action: None,
   };
   match api.post(&ntfy_msg).await {
       Ok(_) => println!("Message sent"),
       Err(_) => println!("Error sending message"),
   }
}

Configuration

let api = NtfyApi::new(NtfySettings {
   host: String::from("https://ntfysh/"),
   authorization: Some(NtfyAuthorization {
       username: String::from("username"),
       password: String::from("password"),
   }),
});

Dependencies

~4–20MB
~226K SLoC