|
| 1 | +--- |
| 2 | +sidebar_position: 1 |
| 3 | +--- |
| 4 | +[//]: # (This file is auto-generated. Please do not modify it yourself.) |
| 5 | + |
| 6 | +# uri_encoded/3 |
| 7 | + |
| 8 | +## Module |
| 9 | + |
| 10 | +This predicate is provided by `uri.pl`. |
| 11 | + |
| 12 | +Load this module before using the predicate: |
| 13 | + |
| 14 | +```prolog |
| 15 | +:- consult('/v1/lib/uri.pl'). |
| 16 | +``` |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +uri_encoded(+Component, -Value, +Encoded) is det. |
| 21 | + |
| 22 | +Encoded is the URI encoding for Value. |
| 23 | + |
| 24 | +Component specifies the URI component where the value is used. It is one of |
| 25 | +`query_value`, `fragment`, `path` or `segment`. |
| 26 | + |
| 27 | +Value and Encoded may be atoms, lists of characters, or lists of character |
| 28 | +codes. Generated values are returned as atoms. |
| 29 | + |
| 30 | +## Signature |
| 31 | + |
| 32 | +```text |
| 33 | +uri_encoded(+Component, +Value, -Encoded) is det |
| 34 | +``` |
| 35 | + |
| 36 | +## Examples |
| 37 | + |
| 38 | +### Decode a raw path atom |
| 39 | + |
| 40 | +This scenario demonstrates how to decode a raw URI path into plain text. |
| 41 | + |
| 42 | +Here are the steps of the scenario: |
| 43 | + |
| 44 | +- **Given** the query: |
| 45 | + |
| 46 | +``` prolog |
| 47 | +consult('/v1/lib/uri.pl'), |
| 48 | +uri_encoded(path, Decoded, foo). |
| 49 | +``` |
| 50 | + |
| 51 | +- **When** the query is run |
| 52 | +- **Then** the answer we get is: |
| 53 | + |
| 54 | +``` yaml |
| 55 | +height: 42 |
| 56 | +gas_used: 4709 |
| 57 | +answer: |
| 58 | + has_more: false |
| 59 | + variables: ["Decoded"] |
| 60 | + results: |
| 61 | + - substitutions: |
| 62 | + - variable: Decoded |
| 63 | + expression: "foo" |
| 64 | +``` |
| 65 | +
|
| 66 | +### Encode a query value with a space |
| 67 | +
|
| 68 | +This scenario demonstrates how to percent-encode a query value. |
| 69 | +
|
| 70 | +Here are the steps of the scenario: |
| 71 | +
|
| 72 | +- **Given** the query: |
| 73 | +
|
| 74 | +``` prolog |
| 75 | +consult('/v1/lib/uri.pl'), |
| 76 | +uri_encoded(query_value, 'foo bar', Encoded). |
| 77 | +``` |
| 78 | + |
| 79 | +- **When** the query is run |
| 80 | +- **Then** the answer we get is: |
| 81 | + |
| 82 | +``` yaml |
| 83 | +height: 42 |
| 84 | +gas_used: 5716 |
| 85 | +answer: |
| 86 | + has_more: false |
| 87 | + variables: ["Encoded"] |
| 88 | + results: |
| 89 | + - substitutions: |
| 90 | + - variable: Encoded |
| 91 | + expression: "'foo%20bar'" |
| 92 | +``` |
0 commit comments