E07671: a service URI needs 'for' before it and an HTTP verb needs 'as' before it
What went wrong
A service is written in one form: 'for' before every URI, and 'as' before an HTTP verb. The service's own URI ('Items for :/items open'), each method's ('byId() as GET for :/{id}') and each operator's ('operator += for :/') all take 'for'; a method that names its verb takes 'as' before it. A declaration with either word missing is this error, reported at the URI or the verb it belongs before.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 657 (How does service URI mapping work with :/path syntax?)
How to fix it
- Write 'for' before the URI: 'Items for :/items', not 'Items :/items'
- Write 'as' before the verb: 'byId() as GET for :/{id}' (not 'byId() GET for :/{id}')
- Each has one reading, so the MCP editing tools (ek9_edit_file, ek9_write_file, ek9_compile) insert the missing word for you. By hand: add the word as above.
The [EXAMPLE] section below shows a service and a method each missing a word, and the same service in its one form.
Common causes
- Following an older example that left 'for' or 'as' out
- Reading 'GET' as an annotation rather than the verb of the declaration
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07671: a service URI needs 'for' before it and an HTTP verb needs 'as' before it
#!ek9 defines module error.e07671.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 //A URI is written after 'for' Addresses :/addresses open //wrong: no 'for' before the URI //An HTTP verb is written after 'as' byId() GET for :/{id} //wrong: no 'as' before the verb -> id as String <- response as HTTPResponse: TextResponse(`address ${id}`)
Fixed: Write 'for' before every URI and 'as' before the HTTP verb
#!ek9 defines module error.e07671.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 byId() as GET for :/{id} -> id as String <- response as HTTPResponse: TextResponse(`address ${id}`) operator += for :/ -> incoming as String :=: CONTENT <- response as HTTPResponse: TextResponse(incoming)
Questions and answers
These Q&A entries show E07671 and its fix:
Found a problem?
If EK9 reported E07671 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.