url

URL generation and encoding utility library


License
MIT

Documentation

url.erl

Provides URL encoding/decoding and generation functions.

Rebar Installation

Add the following to your rebar.config:

{ url, ".*",	{ git, "git://github.com/wrren/url.erl.git", { branch, "master" } } }

Examples

%% URL Generation
"http://localhost/hello" 			= url:join( "http://localhost", ["hello"] ),
"http://localhost/hello" 			= url:join( "http://localhost/", ["hello"] ),
"http://localhost/hello/goodbye" 	= url:join( "http://localhost/", ["hello", "goodbye"] ),
"http://localhost/hello?yo=dawg" 	= url:join( "http://localhost/", ["hello"], #{ "yo" => "dawg" } ),
"http://localhost/hello?yo=dawg" 	= url:join( "http://localhost", ["hello"], #{ "yo" => "dawg" } ),
"http://localhost/hello?yo=dawg" 	= url:join( "http://localhost/", ["hello"], [{"yo", "dawg"}] ).

%% URL Encoding
<<"http%3A%2F%2Flocalhost%3A8080%2Fcallback">>	= url:encode( "http://localhost:8080/callback" ).
	
%% URL Decoding
<<"http://localhost:8080/callback">> = url:decode( <<"http%3A%2F%2Flocalhost%3A8080%2Fcallback">> ).

Join

Given a base URL, path components and query parameters (proplist or map), form a full URL.

url:join( BaseUrl :: string(), PathComponents :: [string()], QueryParameters :: map() | [{ string(), string() }] ) -> URL :: string().

Encode

Encodes special characters using percent-encoding, allowing them to be sent as part of a URL.

url:encode( string() ) -> binary().

Decode

Decodes a URL that's been encoded using the encode function.

url:decode( binary() ) -> string().