E07770: Web Service parameter type must be HTTPRequest for REQUEST

Category: E07xxx Full resolution · Reported in phase: EXPLICIT_TYPE_SYMBOL_DEFINITION · Classification: SERVICE_INCOMPATIBLE_PARAM_TYPE_REQUEST · All error codes

What went wrong

A service parameter is bound with ':=: REQUEST' but its type is not HTTPRequest. REQUEST hands the method the ENTIRE HTTP request, so the parameter it binds must be typed HTTPRequest - a String, Integer or record cannot receive a whole request. (The mirror case - HTTPRequest bound to PATH/QUERY/HEADER instead of REQUEST - is E07790.)

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 1327 (Why must a service parameter bound with :=: REQUEST be...)

How to fix it

  1. Type the REQUEST-bound parameter as HTTPRequest (and it must be the method's only parameter)
  2. For individual values use ':=: PATH', ':=: QUERY' or ':=: HEADER' with a simple type (Integer, String, Date, Time, DateTime, Millisecond, Duration)

The [EXAMPLE] section below shows ':=: REQUEST' on a String, and on an HTTPRequest.

Common causes

  • ':=: REQUEST' on a String or Integer parameter
  • Expecting Spring-style binding, where the annotation and the parameter type are not linked; in EK9 the binding and the type are checked together

See also

  • E07770: REQUEST binding on a non-HTTPRequest parameter (this error)
  • E07790: HTTPRequest bound with PATH/QUERY/HEADER instead of REQUEST
  • E07780: a REQUEST parameter must stand by itself

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E07770: Web Service parameter type must be HTTPRequest for REQUEST

#!ek9
defines module error.e07770.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

      whole() as POST for :/
        ->
          //The whole request is an HTTPRequest
          request as String :=: REQUEST
        <- response as HTTPResponse: TextResponse(request)

Fixed: Take REQUEST as an HTTPRequest

#!ek9
defines module error.e07770.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

      whole() as POST for :/
        -> request as HTTPRequest :=: REQUEST
        <- response as HTTPResponse: TextResponse($request)

Questions and answers

These Q&A entries show E07770 and its fix:

Found a problem?

If EK9 reported E07770 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.