#urlencode #url #encode #uri-url #encode-uri

uri_encode

URI percent-encoding (encodeURI, encodeURIComponent, urlencode)

5 stable releases

1.0.4 Dec 18, 2025
1.0.3 Dec 9, 2024
1.0.2 Jan 17, 2024
1.0.1 Nov 14, 2021

#266 in Encoding

Download history 111/week @ 2025-10-16 1058/week @ 2025-10-23 521/week @ 2025-10-30 99/week @ 2025-11-06 573/week @ 2025-11-13 447/week @ 2025-11-20 230/week @ 2025-11-27 504/week @ 2025-12-04 331/week @ 2025-12-11 195/week @ 2025-12-18 677/week @ 2025-12-25 600/week @ 2026-01-01 533/week @ 2026-01-08 602/week @ 2026-01-15 267/week @ 2026-01-22 286/week @ 2026-01-29

1,705 downloads per month
Used in 3 crates (2 directly)

ISC license

20KB
309 lines

uri_encode

URI percent-encoding for Rust, providing functions equivalent to JavaScript's encodeURI() and encodeURIComponent().

Installation

[dependencies]
uri_encode = "1.0"

Usage

use uri_encode::{encode_uri, encode_uri_component, encode_query_param};

// Encode a complete URL (preserves structure)
let url = encode_uri("https://example.com/path?q=hello world");
assert_eq!(url, "https://example.com/path?q=hello%20world");

// Encode a URL component (more aggressive)
let component = encode_uri_component("path/with spaces");
assert_eq!(component, "path%2fwith%20spaces");

// Encode query parameters (spaces become +)
let param = encode_query_param("hello world");
assert_eq!(param, "hello+world");

Functions

encode_uri

Encodes a complete URI while preserving its structure. Equivalent to JavaScript's encodeURI().

Preserves: A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; , / ? : @ & = + $ #

encode_uri("https://example.com/hello world?name=foo bar")
// => "https://example.com/hello%20world?name=foo%20bar"

encode_uri_component

Encodes a URI component such as a path segment or query value. Equivalent to JavaScript's encodeURIComponent().

Preserves: A-Z a-z 0-9 - _ . ! ~ * ' ( )

encode_uri_component("hello world&foo=bar")
// => "hello%20world%26foo%3dbar"

encode_query_param

Encodes a query parameter using application/x-www-form-urlencoded format. Spaces become +.

encode_query_param("John Doe")
// => "John+Doe"

Character Encoding Reference

Character encode_uri encode_uri_component encode_query_param
space %20 %20 +
/ / %2f /
? ? %3f ?
& & %26 &
= = %3d =
# # %23 #

Features

  • Zero dependencies
  • No unsafe code (#![forbid(unsafe_code)])
  • Works with &str, String, or any type implementing AsRef<str>

License

ISC

No runtime deps