Changes between Version 37 and Version 38 of S3/S3REST/URLFormat
- Timestamp:
- 12/23/13 10:53:54 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
S3/S3REST/URLFormat
v37 v38 4 4 - see also: [wiki:S3/S3REST/Methods Standard Methods] 5 5 6 == Basic URL Syntax==6 == URL Format == 7 7 8 8 - ''Parts in { } mark optional parts, [ A | B ] indicates alternatives'' 9 9 10 === Basic URL Format === 11 10 12 The basic URL format is: 11 13 12 !http:// '''server''' / ''' path''' / '''prefix''' / '''name'''{ /<'''arguments'''> }{ ?<'''query'''> }14 !http:// '''server''' / '''application''' / '''prefix''' / '''name'''{ /<'''arguments'''> }{ ?<'''query'''> } 13 15 14 15 16 http:// vita.sahanafoundation.org/eden/hms/hospital/1/bed_capacity/create17 16 ''Example:'' 17 {{{ 18 http://demo.eden.sahanafoundation.org/eden/org/office/4/human_resource?~.person_id$first_name__like=Nor* 19 }}} 18 20 19 * '''server''' ('''{{{vita.sahanafoundation.org}}}''') is the server, '''path''' ('''{{{/eden}}}''') the path to the application 21 ||=''Part''=||=''Explanation''=||=''Example''=|| 22 ||'''Server'''||the server URL||{{{demo.eden.sahanafoundation.org}}}|| 23 ||'''Application'''||the web2py application name||{{{eden}}}|| 24 ||'''Prefix'''||the module prefix||{{{org}}}|| 25 ||'''Name'''||the resource name||{{{office}}}|| 26 ||'''Arguments'''||''see arguments list format''||{{{4/human_resource}}}|| 27 ||'''Query'''||''see query format''||{{{~.person_id$first_name__like=Nor*}}}|| 20 28 21 * '''prefix''' ('''{{{/hms}}}''') is the application prefix (="module" name) of the resource 22 * '''name''' ('''{{{/hospital}}}''') is the resource name (without prefix) 29 === Arguments List Format === 23 30 24 The '''arguments'''list consists of:31 The arguments list consists of: 25 32 26 33 { /'''id''' }{ / [ '''method''' | '''component''' { /'''component_id''' } { /'''method''' } ] } 27 34 28 * '''id''' ('''{{{/1}}}''') is a record ID in the main resource 29 * '''component''' ('''{{{/bed_capacity}}}''') is a component resource name (without prefix) 30 * '''component_id''' is a record ID in the componentresource31 * '''method''' ('''{{{/create}}}''') is a URL [wiki:S3XRC/RESTfulAPI/Methods method] 35 ''Example:'' 36 {{{ 37 4/human_resource 38 }}} 32 39 33 For the '''query''' syntax, see below 34 == Basic Query Format == 40 ||=''Part''=||=''Explanation''=||=''Example''=|| 41 ||'''ID'''||the master record ID||{{{4}}}|| 42 ||'''Method'''||the resource method (e.g. /create or /summary)||''not present in example''|| 43 ||'''Component'''||the component resource (projected table)||{{{human_resource}}}|| 44 ||'''Component ID'''||the component record ID||''not present in example''|| 35 45 36 The basic query format is: '''resource'''.{'''foreign key'''$}'''field'''{'''operator'''}='''value(s)''' 46 === Query Format === 37 47 38 * '''resource''' is the name of the resource or component (without prefix) 39 * '''foreign key''' is the name of the foreign key field 40 * '''field''' is the name of the field in the target table 41 * '''operator''' is the operator 42 * '''value(s)''' is the value or a comma-separated list of values to test against (a comma will be treated as OR) 48 The basic query format is: 43 49 44 The tilde {{{~}}} as resource name is interpreted as "this resource" (=the master resource addressed by the URL). 50 '''field-selector'''{'''operator'''}='''value(s)''' 45 51 46 {{{None}}} as value can be specified as {{{NONE}}} in the URL (all-uppercase). 52 ''Example:'' 53 {{{ 54 ~.person_id$first_name__like=Nor* 55 }}} 47 56 48 Values with commas are always treated as a list of values. A value enclosed in double quotes {{{"}}} is treated as string constant - i.e. commas and {{{NONE}}} inside the string will not be interpreted in this case. 57 ||=''Part''=||=''Explanation''=||=''Example''=|| 58 ||'''Field Selector'''||the field selector||{{{~.person_id$first_name}}}|| 59 ||'''Operator'''||the query operator||{{{__like}}}|| 60 ||'''Value(s)'''||the search values||{{{Nor*}}}|| 49 61 50 It is possible to chain {{{$}}} selectors like in {{{resource.foreign_key$foreign_key$fieldname=value}}} to select fields in tables which are two or more forward references away. 62 * {{{NONE}}} as value is interpreted as a NULL-value (=Python {{{None}}}) 63 * multiple values can be specified separated by commas 64 * a value enclosed in double quotes {{{"}}} is treated as string constant - i.e. commas and {{{NONE}}} inside the string will not be interpreted 65 * only the {{{__like}}} operator interprets the asterisk {{{*}}} as wildcard (all other operators do not!) 51 66 52 Supported operators: 67 ==== Field Selectors ==== 68 69 The general field selector syntax is: 70 71 '''alias'''.{'''left-key''':'''link-table'''.}{'''foreign-key'''$}['''field-selector''' | '''field-name'''] 72 73 ''Example:'' 74 {{{ 75 ~.person_id$first_name 76 }}} 77 78 ||=''Part''=||=''Explanation''=||=''Example''=|| 79 ||'''Alias'''||is the alias of the component without prefix (note that components may use aliases different from their table name). ||{{{~}}}|| 80 ||'''Left Key'''||the foreign key field in a backward-reference (=link table points back to master/component), can be omitted if not ambiguous|| || 81 ||'''Link Table||the table name of the backward-referencing table (incl. prefix)|| || 82 ||'''Foreign Key'''||foreign key field in a forward-reference (=component points to a referenced table), ||{{{person_id}}}|| 83 ||'''Field Name'''||the target field name||{{{first_name}}}|| 84 85 * For the master table of of the request, the '''alias''' is the tablename without prefix or just {{{~}}} 86 * Foreign key references can be chained (separated by $) if the referenced table is more than one reference level away, like in {{{resource.foreign_key$foreign_key$fieldname=value}}} 87 * "integer", "list:reference" or virtual fields are not real foreign keys and can therefore not be used for $-joins 88 * Field selectors represent the ''path'' to the target field (interpreted left-to-right), starting with the master resource or a component of it 89 * Queries with invalid or unresolvable field selectors are ignored (but logged on stderr if in debug mode) 90 91 ==== Query Operators ==== 53 92 54 93 ||'''Operator'''||'''Method'''||'''Comments|| … … 63 102 ||!__belongs||reverse containment|||| 64 103 65 To negate a query, append {{{!}}} to the operator, e.g. {{{resource.fieldname__like!=value}}}. 104 * to negate a query, append {{{!}}} to the operator, e.g. {{{resource.fieldname__like!=value}}} 105 * the {{{__like}}} operator works case-insensitive, whereas {{{__contains}}} is case-sensitive. 66 106 67 The {{{like}}} operator works case-insensitive, whereas {{{contains}}} is case-sensitive. 68 == Field Queries == 107 ==== Examples ==== 69 108 70 Field names in URL queries must be prefixed by the resource alias, followed by a "." dot, like: 71 72 Master resource: 109 Filtering persons by their first name: 73 110 74 111 {{{ … … 76 113 }}} 77 114 78 Master resources use their table name without controller prefix as alias, whereas components can have a context-dependent alias (which must be used here). 79 80 The tilde {{{~}}} refers to the master resource addressed by the URL: 115 The tilde {{{~}}} refers to the master resource addressed by the URL, i.e. {{{pr_person}}} in this case: 81 116 82 117 {{{ … … 84 119 }}} 85 120 86 This refers to the {{{first_name}}} field in the {{{pr_person}}} table. 87 88 Component: 121 Filtering offices by the name of their location: 89 122 90 123 {{{ 91 / pr/person?address.city__like=*Oslo*124 /org/office?~.location_id$name__like=Osl* 92 125 }}} 93 126 94 Note that any component of the master resource can be queried, even if it is not addressed by the URL.95 96 To query a field in a referenced record, append the foreign key field name followed by a "$" sign to the resource name prefix.97 98 {{{99 /pr/person?person.location_id$lat__lt=55.0100 }}}101 102 This requires that the respective foreign key field is defined as "reference" type ("integer", "list:reference" or virtual fields are not real foreign keys and can therefore not be used for $-joins).103 127 104 128 == Boundary Box Queries ==