4 releases (2 breaking)

0.6.2 Aug 26, 2022
0.6.1 Aug 22, 2022
0.5.0 Aug 22, 2022
0.4.0 Aug 22, 2022

#361 in HTTP client

Download history 456/week @ 2024-04-09 294/week @ 2024-04-16 510/week @ 2024-04-23 139/week @ 2024-04-30 705/week @ 2024-05-07 913/week @ 2024-05-14 1006/week @ 2024-05-21 608/week @ 2024-05-28 400/week @ 2024-06-04 520/week @ 2024-06-11 712/week @ 2024-06-18 1230/week @ 2024-06-25 775/week @ 2024-07-02 1005/week @ 2024-07-09 86/week @ 2024-07-16 78/week @ 2024-07-23

2,262 downloads per month

MIT license

9KB
171 lines

Format URLs for fetch requests using templates and substitution values.

Usage

use format_url::FormatUrl;

let url = FormatUrl::new("https://api.example.com/")
    .with_path_template("/user/:name")
    .with_substitutes(vec![("name", "alex")])
    .with_query_params(vec![("active", "true")])
    .format_url();

assert_eq!(url, "https://api.example.com/user/alex?active=true");

Wishlist

  • Support for lists and nested values. (serde_urlencoded -> serde_qs)
  • Support receiving query params as any value serde_urlencoded or serde_qs can serialize.
  • Support receiving path template substitutes as a (Hash)Map, perhaps even a struct with matching fields.

lib.rs:

Format URLs for fetch requests using templates and substitution values.

Usage

use format_url::FormatUrl;

let url = FormatUrl::new("https://api.example.com/")
    .with_path_template("/user/:name")
    .with_substitutes(vec![("name", "alex")])
    .with_query_params(vec![("active", "true")])
    .format_url();

assert_eq!(url, "https://api.example.com/user/alex?active=true");

Wishlist

  • Support for lists and nested values. (serde_urlencoded -> serde_qs)
  • Support receiving query params as any value serde_urlencoded or serde_qs can serialize.
  • Support receiving path template substitutes as a (Hash)Map, perhaps even a struct with matching fields.

Dependencies

~14KB