Did you know ... | Search Documentation: |
Packs (add-ons) for SWI-Prolog |
Title: | URI quasiquotations |
---|---|
Rating: | Not rated. Create the first rating! |
Latest version: | 0.3.0 |
SHA1 sum: | 50090a747f13286635d12072e9ca23dd565972e4 |
Author: | Michael Hendricks <michael@ndrix.org> |
Maintainer: | Michael Hendricks <michael@ndrix.org> |
Packager: | Michael Hendricks <michael@ndrix.org> |
Home page: | http://packs.ndrix.com/uri_qq/index.html |
Download URL: | http://packs.ndrix.com/uri_qq/uri_qq-0.3.0.tgz |
Requires: | function_expansion |
No reviews. Create the first review!.
Version | SHA1 | #Downloads | URL |
---|---|---|---|
0.3.0 | 50090a747f13286635d12072e9ca23dd565972e4 | 34 | http://packs.ndrix.com/uri_qq/uri_qq-0.3.0.tgz |
0.2.0 | 92a9468d34ae8bf8d7c10821258243cee889c4cf | 2 | http://packs.ndrix.com/uri_qq/uri_qq-0.2.0.tgz |
0.1.0 | 36f539f157bbe432ddda872c139599a3789ef094 | 7 | http://packs.ndrix.com/uri_qq/uri_qq-0.1.0.tgz |
0.0.1 | 976899ecad733cae304abc7526044aa2afb96c58 | 2 | http://packs.ndrix.com/uri_qq/uri_qq-0.0.1.tgz |
:- use_module(library(uri_qq)). :- use_module(library(http/http_client)). main :- Path = search, Params = [q='prolog is awesome'], http_get({|uri||google.com/$Path?$Params|}, Content, []), write(Content).
This module makes it easy to build complex URIs out of component parts. All necessary escaping is done automatically. In nearly all cases, this is more convenient than using library(uri) directly.
In most circumstances, you can just use $Name
anywhere inside the
URI and the runtime value of variable Name will be inserted at that
location. library(uri_qq)
also supports the following less obvious
features:
It quickly gets annoying to type and read `http://` all over the place. If you omit the scheme in a URI template, `http://` is inserted automatically. See the Synopsis above.
Also see Relative References below.
There are two ways to build dynamic queries for a URI. The first way is to interpolate a key or a value directly in the URI template:
Name = name, Value = value, U = {|uri||example.com/q?name=$Value|}, U = {|uri||example.com/q?$Name=value|},
The second way is to build a dict or a list of Key=Value
pairs and interpolate
the entire query. This example builds the same U value as above:
Query = _{name: value}, U = {|uri||example.com/q?$Query|},
Sometimes you need to create many URIs relative to a single base URI. To avoid repeating content and to get all the convenience you expect from relative URIs, you can specify a local base URI as the first argument of the quasiquoter like this:
Base = 'http://www.example.org/path/to/', U1 = {|uri(Base)||foo#1|}, U2 = {|uri(Base)||foo#2|}, U3 = {|uri(Base)||../goes/elsewhere|},
When it encounters a relative URI in the clause, it's resolved against the base URI to produce an absolute URI.
a/b/c
instead of just atomsUsing SWI-Prolog 6.3.16 or later:
?- pack_install(uri_qq).
For repository and pull requests, see https://github.com/mndrix/uri_qq
This module uses semantic versioning.
Pack contains 5 files holding a total of 10.1K bytes.