E07680: URI with place holder variable not supported in this context
What went wrong
A service's own URI holds a path variable ('{region}'). The service URI is fixed: it is where the service is mounted. Path variables belong in the URI of a METHOD (or operator) of the service, where each is bound to a parameter.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 945 (How do HTTP verbs, URI path variables, and parameter q...)
How to fix it
- Remove the variable from the service's URI
- Put it in the method's URI instead ('byRegion() as GET for :/{region}/{id}') and take it as a parameter of the same name
The [EXAMPLE] section below shows a service mounted at ':/addresses/{region}', and the same variable moved into the method's URI.
Common causes
- Treating the service URI as a route prefix that can capture values
- Moving a route from another framework where the controller path takes variables
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07680: URI with place holder variable not supported in this context
#!ek9 defines module error.e07680.bad defines class TextResponse with trait of HTTPResponse text as String? default private TextResponse() TextResponse() -> body as String this.text: body override contentType() as pure <- rtn as String: "text/plain" override content() <- rtn as Bytes: Bytes().withUtf8(text) override status() as pure <- rtn as Integer: 200 default operator ? defines service //The service's own URI is fixed Addresses for :/addresses/{region} open byId() as GET for :/{id} -> id as String <- response as HTTPResponse: TextResponse(`address ${id}`)
Fixed: Keep the service URI fixed; put variables in the methods
#!ek9 defines module error.e07680.good defines class TextResponse with trait of HTTPResponse text as String? default private TextResponse() TextResponse() -> body as String this.text: body override contentType() as pure <- rtn as String: "text/plain" override content() <- rtn as Bytes: Bytes().withUtf8(text) override status() as pure <- rtn as Integer: 200 default operator ? defines service Addresses for :/addresses open //Variables go in the method's URI byRegion() as GET for :/{region}/{id} -> region as String id as String <- response as HTTPResponse: TextResponse(`${region} ${id}`)
Found a problem?
If EK9 reported E07680 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.