1 USING: assocs hashtables help.markup help.syntax
2 io.streams.string io.files io.pathnames kernel strings present
7 { $class-description "The class of URLs. The slots correspond to the standard components of a URL." } ;
10 { $values { "url" url } }
11 { $description "Creates an empty URL." } ;
14 { $values { "obj" object } { "url" url } }
15 { $description "Converts an object into a URL. If the object is already a URL, does nothing; if it is a string, then it is parsed as a URL." }
16 { $errors "Throws an error if the object is of the wrong type, or if it is a string which is not a valid URL." }
18 "If we convert a string to a URL and print it out again, it will print similarly to the input string, except some normalization may have occurred:"
20 "USING: accessors prettyprint urls ;"
21 "\"http://www.apple.com\" >url ."
22 "URL\" http://www.apple.com/\""
24 "We can examine the URL object:"
26 "USING: accessors io urls ;"
27 "\"http://www.apple.com\" >url host>> print"
30 "A relative URL does not have a protocol, host or port:"
32 "USING: accessors prettyprint urls ;"
33 "\"file.txt\" >url protocol>> ."
39 { $syntax "URL\" url...\"" }
40 { $description "URL literal syntax." }
43 "USING: accessors prettyprint urls ;"
44 "URL\" http://factorcode.org:80\" port>> ."
50 { $values { "base" url } { "url" url } { "url'" url } }
51 { $description "Builds a URL by filling in missing components of " { $snippet "url" } " from " { $snippet "base" } "." }
54 "USING: prettyprint urls ;"
55 "URL\" http://factorcode.org\""
56 "URL\" binaries.fhtml\" derive-url ."
57 "URL\" http://factorcode.org/binaries.fhtml\""
60 "USING: prettyprint urls ;"
61 "URL\" http://www.truecasey.com/drinks/kombucha\""
62 "URL\" master-cleanser\" derive-url ."
63 "URL\" http://www.truecasey.com/drinks/master-cleanser\""
68 { $values { "url" url } }
69 { $description "If the URL does not specify a port number, fill in the default for the URL's protocol. If the protocol is unknown, the port number is not changed." }
70 { $side-effects "url" }
73 "USING: accessors prettyprint urls ;"
74 "URL\" https://concatenative.org\" ensure-port port>> ."
80 { $values { "string" string } { "host" string } { "port" { $maybe integer } } }
81 { $description "Splits a string of the form " { $snippet "host:port" } " into a host and a port number. If the port number is not specified, outputs " { $link f } "." }
82 { $notes "This word is used by " { $link >url } ". It can also be used directly to parse " { $snippet "host:port" } " strings which are not full URLs." }
85 "USING: prettyprint urls ;"
86 "\"sbcl.org:80\" parse-host .s"
92 { $values { "protocol" "a protocol string" } { "port" { $maybe integer } } }
93 { $description "Outputs the port number associated with a protocol, or " { $link f } " if the protocol is unknown." } ;
97 { "url" url } { "key" string }
98 { "value" { $maybe string } } }
99 { $description "Outputs the URL-decoded value of a URL query parameter." }
103 "URL\" http://food.com/calories?item=French+Fries\""
104 "\"item\" query-param print"
109 HELP: set-query-param
110 { $values { "url" url } { "value" object } { "key" string } }
111 { $description "Sets a query parameter. The value can be any object supported by " { $link present } ", or " { $link f } ", in which case the key is removed." }
112 { $notes "This word always returns the same URL object that was input. This allows for a ``pipeline'' coding style, where several query parameters are set in a row. Since it mutates the input object, you must " { $link clone } " it first if it is literal, as in the below example."
116 <" USING: kernel http.client urls ;
117 URL" http://search.yahooapis.com/WebSearchService/V1/webSearch" clone
118 "concatenative programming (NSFW)" "query" set-query-param
119 "1" "adult_ok" set-query-param
122 "(For a complete Yahoo! search web service implementation, see the " { $vocab-link "yahoo" } " vocabulary.)"
124 { $side-effects "url" } ;
127 { $values { "url" url } { "url'" url } }
128 { $description "Outputs a new URL with the same path and query components as the input value, but with the protocol, host and port set to " { $link f } "." }
131 "USING: prettyprint urls ;"
132 "URL\" http://factorcode.org/binaries.fhtml\""
134 "URL\" /binaries.fhtml\""
141 { "?" "a boolean" } }
142 { $description "Tests whether a URL is relative." } ;
144 HELP: secure-protocol?
145 { $values { "protocol" string } { "?" "a boolean" } }
146 { $description "Tests if protocol connections must be made with secure sockets (SSL/TLS)." }
149 "USING: prettyprint urls ;"
150 "\"https\" secure-protocol? ."
156 { $values { "url" url } { "addr" "an address specifier" } }
157 { $description "Outputs an address specifier for use with " { $link "network-connection" } "." }
160 "USING: prettyprint urls ;"
161 "URL\" ftp://ftp.cdrom.com\" url-addr ."
162 "T{ inet { host \"ftp.cdrom.com\" } { port 21 } }"
166 HELP: url-append-path
167 { $values { "path1" string } { "path2" string } { "path" string } }
168 { $description "Like " { $link append-path } ", but intended for use with URL paths and not filesystem paths." } ;
170 ARTICLE: "url-utilities" "URL implementation utilities"
171 { $subsection parse-host }
172 { $subsection secure-protocol? }
173 { $subsection url-append-path } ;
175 ARTICLE: "urls" "URL objects"
176 "The " { $vocab-link "urls" } " vocabulary implements a URL data type. The benefit of using a data type to prepresent URLs rather than a string is that the parsing, printing and escaping logic is encapsulated and reused, rather than re-implemented in a potentially buggy manner every time."
178 "URL objects are used heavily by the " { $vocab-link "http" } " and " { $vocab-link "furnace" } " vocabularies, and are also useful on their own."
180 "The class of URLs, and a constructor:"
182 { $subsection <url> }
183 "Converting strings to URLs:"
185 "URLs can be converted back to strings using the " { $link present } " word."
187 "URL literal syntax:"
188 { $subsection POSTPONE: URL" }
190 { $subsection derive-url }
191 { $subsection relative-url }
192 { $subsection ensure-port }
193 { $subsection query-param }
194 { $subsection set-query-param }
195 "Creating " { $link "network-addressing" } " from URLs:"
196 { $subsection url-addr }
197 "The URL implemention encodes and decodes components of " { $link url } " instances automatically, but sometimes this functionality is needed for non-URL strings."
198 { $subsection "url-encoding" }
199 "Utility words used by the URL implementation:"
200 { $subsection "url-utilities" } ;