2016-01-09 03:03:50 +00:00
|
|
|
urilib
|
|
|
|
======
|
|
|
|
[RFC-3986](https://tools.ietf.org/html/rfc3986) URI Library for Erlang.
|
|
|
|
|
2016-01-09 04:27:38 +00:00
|
|
|
[![Build Status](https://travis-ci.org/gmr/urilib.svg?branch=master)](https://travis-ci.org/gmr/urilib) [![codecov.io](https://codecov.io/github/gmr/urilib/coverage.svg?branch=master)](https://codecov.io/github/gmr/urilib?branch=master)
|
2016-01-09 04:27:04 +00:00
|
|
|
|
2016-01-09 04:40:55 +00:00
|
|
|
Example Usage
|
|
|
|
-------------
|
|
|
|
```erlang
|
|
|
|
-include_lib("urilib.h").
|
|
|
|
|
|
|
|
URI = urilib:parse_uri("http://foo:bar@www.google.com/search?baz=qux#corgie"),
|
|
|
|
io:format("Parsed URI: ~p~n", [URI]).
|
|
|
|
|
|
|
|
URL = urllib:build(#url{scheme=http, host="www.google.com", path="/search", query=[{"foo", "bar"}], fragment="baz"}),
|
|
|
|
io:format("Built URL: ~s~n", [URL]).
|
|
|
|
```
|
|
|
|
|
|
|
|
Records
|
|
|
|
-------
|
|
|
|
|
|
|
|
#### authority ####
|
|
|
|
```erlang
|
|
|
|
#{host :: string(), port :: integer()}).
|
|
|
|
```
|
|
|
|
|
|
|
|
#### userinfo ####
|
|
|
|
```erlang
|
|
|
|
#{username :: string(), password :: string()}).
|
|
|
|
```
|
|
|
|
|
|
|
|
#### uri ####
|
|
|
|
```erlang
|
|
|
|
#{scheme :: atom(),
|
|
|
|
userinfo :: #userinfo{},
|
|
|
|
authority :: #authority{},
|
|
|
|
path :: string(),
|
|
|
|
query :: list(),
|
|
|
|
fragment :: string()}).
|
|
|
|
```
|
|
|
|
|
|
|
|
#### url ####
|
|
|
|
```erlang
|
|
|
|
#{scheme :: atom(),
|
|
|
|
username :: string(),
|
|
|
|
password :: string(),
|
|
|
|
host :: string(),
|
|
|
|
port :: integer(),
|
|
|
|
path :: string(),
|
|
|
|
query :: list(),
|
|
|
|
fragment :: string()}).
|
|
|
|
```
|
|
|
|
|
2016-01-09 03:03:50 +00:00
|
|
|
API
|
|
|
|
---
|
|
|
|
|
2016-01-09 04:27:04 +00:00
|
|
|
<a name="build-1"></a>
|
|
|
|
|
|
|
|
### build/1 ###
|
2016-01-09 04:30:19 +00:00
|
|
|
```erlang
|
|
|
|
build(Uri::Value) -> URI
|
|
|
|
```
|
2016-01-09 04:27:04 +00:00
|
|
|
<ul class="definitions"><li><code>Value = #uri{} | #url{}</code></li><li><code>URI = string()</code></li></ul>
|
|
|
|
|
|
|
|
Returns a URI from the record passed in.
|
|
|
|
|
|
|
|
<a name="decode-1"></a>
|
|
|
|
|
|
|
|
### decode/1 ###
|
|
|
|
|
2016-01-09 04:30:19 +00:00
|
|
|
```erlang
|
|
|
|
decode(Value) -> DecodedValue
|
|
|
|
```
|
2016-01-09 04:27:04 +00:00
|
|
|
|
|
|
|
<ul class="definitions"><li><code>Value = string()</code></li><li><code>DecodeValue = string()</code></li></ul>
|
|
|
|
|
|
|
|
Decode a percent encoded string value.
|
|
|
|
|
|
|
|
<a name="decode_plus-1"></a>
|
|
|
|
|
|
|
|
### decode_plus/1 ###
|
|
|
|
|
2016-01-09 04:30:19 +00:00
|
|
|
```erlang
|
2016-01-09 04:31:08 +00:00
|
|
|
decode_plus(Value) -> DecodedValue
|
2016-01-09 04:30:19 +00:00
|
|
|
```
|
2016-01-09 04:27:04 +00:00
|
|
|
|
|
|
|
<ul class="definitions"><li><code>Value = string()</code></li><li><code>DecodeValue = string()</code></li></ul>
|
|
|
|
|
|
|
|
Decode a percent encoded string value that uses pluses for spaces.
|
|
|
|
|
|
|
|
Note: The use of plus for space is defined in RFC-1630 but does not appear
|
|
|
|
in RFC-3986.
|
|
|
|
|
|
|
|
<a name="encode-1"></a>
|
|
|
|
|
|
|
|
### encode/1 ###
|
|
|
|
|
2016-01-09 04:30:19 +00:00
|
|
|
```erlang
|
2016-01-09 04:31:08 +00:00
|
|
|
encode(Value) -> EncodedValue
|
2016-01-09 04:30:19 +00:00
|
|
|
```
|
2016-01-09 04:27:04 +00:00
|
|
|
|
|
|
|
<ul class="definitions"><li><code>Value = string()</code></li><li><code>EncodedValue = string()</code></li></ul>
|
|
|
|
|
|
|
|
Percent encode a string value.
|
|
|
|
|
|
|
|
<a name="encode_plus-1"></a>
|
|
|
|
|
|
|
|
### encode_plus/1 ###
|
|
|
|
|
2016-01-09 04:30:19 +00:00
|
|
|
```erlang
|
2016-01-09 04:31:08 +00:00
|
|
|
encode_plus(Value) -> EncodedValue
|
2016-01-09 04:30:19 +00:00
|
|
|
```
|
2016-01-09 04:27:04 +00:00
|
|
|
|
|
|
|
<ul class="definitions"><li><code>Value = string()</code></li><li><code>EncodedValue = string()</code></li></ul>
|
|
|
|
|
|
|
|
Percent encode a string value similar to encode/1, but encodes spaces with a
|
|
|
|
plus (+) instead of %20. This function can be used for encoding query arguments.
|
|
|
|
|
|
|
|
Note: The use of plus for space is defined in RFC-1630 but does not appear
|
|
|
|
in RFC-3986.
|
|
|
|
|
|
|
|
<a name="parse_uri-1"></a>
|
|
|
|
|
|
|
|
### parse_uri/1 ###
|
|
|
|
|
2016-01-09 04:30:19 +00:00
|
|
|
```erlang
|
2016-01-09 04:31:08 +00:00
|
|
|
parse_uri(URI) -> ParsedURI
|
2016-01-09 04:30:19 +00:00
|
|
|
```
|
2016-01-09 04:27:04 +00:00
|
|
|
|
|
|
|
<ul class="definitions"><li><code>URI = string()</code></li><li><code>ParsedURI = #uri{}</code></li></ul>
|
|
|
|
|
|
|
|
Parse a URI string returning the parsed data as a record
|
|
|
|
|
|
|
|
<a name="parse_url-1"></a>
|
|
|
|
|
|
|
|
### parse_url/1 ###
|
|
|
|
|
2016-01-09 04:30:19 +00:00
|
|
|
```erlang
|
2016-01-09 04:31:08 +00:00
|
|
|
parse_url(URL) -> ParsedURL
|
2016-01-09 04:30:19 +00:00
|
|
|
```
|
2016-01-09 04:27:04 +00:00
|
|
|
|
|
|
|
<ul class="definitions"><li><code>URI = string()</code></li><li><code>ParsedURL = #url{}</code></li></ul>
|
|
|
|
|
|
|
|
Parse a URL string returning the parsed data as a record
|
|
|
|
|