E07780: Web Service type HTTPRequest can only be used by itself

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

What went wrong

You have HTTPRequest parameter alongside other parameters, but HTTPRequest must be the only parameter when used.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 1328 (Why can't I mix HTTPRequest with other parameters in a...)

How to fix it

  1. Use HTTPRequest alone - extract values from it inside method
  2. Or use individual parameters without HTTPRequest

The [EXAMPLE] section below shows a ':=: REQUEST' parameter beside a ':=: QUERY' one, then the whole request taken alone in one method and the individual values in another.

Common causes

  • Mixing ':=: REQUEST' with ':=: QUERY' or ':=: PATH' parameters
  • Trying to have both full request and individual params

See also

  • E07780: HTTPRequest mixed with other params (this error)
  • E07770: ':=: REQUEST' on a parameter that is not an HTTPRequest

Examples

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

Fails with E07780: Web Service type HTTPRequest can only be used by itself

#!ek9
defines module error.e07780.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 already holds every query value
          request as HTTPRequest :=: REQUEST
          count as Integer :=: QUERY "count"
        <- response as HTTPResponse: TextResponse(`${request} ${count}`)

Fixed: Take the whole request alone, or the individual values

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

      //Either the whole request, alone...
      whole() as POST for :/
        -> request as HTTPRequest :=: REQUEST
        <- response as HTTPResponse: TextResponse($request)

      //...or the individual values
      parts() as POST for :/parts
        ->
          count as Integer :=: QUERY "count"
          incoming as String :=: CONTENT
        <- response as HTTPResponse: TextResponse(`${count} ${incoming}`)

Questions and answers

These Q&A entries show E07780 and its fix: