Skip to content

Latest commit

 

History

History
54 lines (45 loc) · 1.33 KB

README.md

File metadata and controls

54 lines (45 loc) · 1.33 KB

Cuis-Smalltalk-URI

See also https://codeberg.org/auverlot/Cuis-Smalltalk-URI.

Construction

| uri |
uri := URI new
    scheme: #https;
    userinfo: 'john:1234';
    host: 'www.domain.com';
    port: 8080;
    path: '/folder/file';
    query: {'id' -> 42. 'name' -> 'john.doe'};
    fragment: 'row=1';
    yourself.
uri asString "https://john:1234@www.domain.com:8080/folder/file?id=42&name=john.doe#row=1"

Parsing

| uri |
uri := URI fromString: 'https://john:1234@www.domain.com:8080/folder/file?id=42&name=john.doe#row=1'.
uri scheme. "#https"
uri username. "john"
uri password. "1234"
uri host. "www.domain.com"
uri port. "8080"
uri path asString. "/folder/file"
uri query. "id=42&name=john.doe"
uri fragment "row=1"

Query Dictionaries

| uri query |
uri := URI fromString: 'https://john:1234@www.domain.com:8080/folder/file?id=42&name=john.doe#row=1'.
query := uri queryDictionary.
query at: 'id'. "42"
query at: 'name' "john.doe"

Relative URIs

| baseUri relativeUri targetUri |
baseUri := URI fromString: 'https://john:1234@www.domain.com:8080/folder/file?id=42&name=john.doe#row=1'.
relativeUri := URI fromString: 'anotherFile#row=2'.
targetUri := relativeUri relativeTo: baseUri.
targetUri asString "https://john:1234@www.domain.com:8080/folder/anotherFile#row=2"