url-constructor 0.1.0

Simple URL builder
Documentation
  • Coverage
  • 8.33%
    1 out of 12 items documented0 out of 11 items with examples
  • Size
  • Source code size: 23.89 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.47 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • ryanYtan/url-constructor
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ryanYtan

Overview

A simple URL constructor with a bit more customizability.

If you do use this library, note that it does not do any error handling nor sanitation of inputs. Do verify the inputs before passing them to the builder (and experiment with the output).

Quick Start

In Cargo.toml:

[dependencies]
url-constructor = "0.1.0"

To create a URL:

use url_constructor::UrlConstructor;

let url = UrlConstructor::new()
    .scheme("http")
    .userinfo("alex:password1")
    .subdomain("api")
    .host("google.com")
    .port(8080)
    .subdir("v2")
    .subdir("users")
    .param("salary", ">10000")
    .param("lastName", "Wallace")
    .fragment("id")
    .build()

assert_eq!(
    url,
    "http://alex:password1@api.google.com:8080/v2/users?lastName=Wallace&salary=>10000#id"
)

Specifications

These are the current "quirks" of the constructor

  • The default scheme is https, there are no defaults for the other components
  • If the scheme is set to the empty string, then the :// part of the URL will not be returned
  • Subdomains are returned left-to-right according to the order in which it is called (see example above)
  • Control characters such as &, ?, /, # and @ are automatically added to their respectively URL components (note: no checks are made to prevent duplicates)
  • Defining each part of the host using the subdomain method should yield the same result as using host directly
  • Multiplicity of each component:
    • scheme: 0...1
    • userinfo: 0...1
    • subdomain: 0...*
    • host: 0...1
    • port: 0...1
    • subdir: 0...*
    • param: 0...*
    • fragment: 0...*