E07790: Web Service parameter type cannot be HTTPRequest
What went wrong
A service parameter is typed HTTPRequest but is not bound with ':=: REQUEST' - it is a PATH, QUERY or HEADER parameter (the default for a path segment). Those bindings parse a single value from the request, so the parameter must be a simple type; the whole request is only available through ':=: REQUEST'. (The mirror case - ':=: REQUEST' on a non-HTTPRequest parameter - is E07770.)
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 868 (Why can't I use HTTPRequest as a path parameter type in E...)
How to fix it
- For a path/query/header value use a simple type: Integer, String, Date, Time, DateTime, Millisecond, Duration
- If you need the whole request, bind it with ':=: REQUEST' as the only parameter
The [EXAMPLE] section below shows an HTTPRequest read from a query value, then the query read as a String and the whole request taken with ':=: REQUEST' in a method of its own.
Common causes
- HTTPRequest used as a path parameter type
- Wanting the full request in a method that also takes individual values
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07790: Web Service parameter type cannot be HTTPRequest
#!ek9 defines module error.e07790.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 Addresses for :/addresses open search() as GET for :/search -> //A query value is text, never the whole request request as HTTPRequest :=: QUERY "q" <- response as HTTPResponse: TextResponse($request)
Fixed: Use HTTPRequest only with REQUEST
#!ek9 defines module error.e07790.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 search() as GET for :/search -> term as String :=: QUERY "q" <- response as HTTPResponse: TextResponse(term) whole() as POST for :/ -> request as HTTPRequest :=: REQUEST <- response as HTTPResponse: TextResponse($request)
Questions and answers
These Q&A entries show E07790 and its fix: