E07750: Web Service return type must be compatible with HTTPResponse

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

What went wrong

A service method returns a type that isn't compatible with HTTPResponse.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 890 (Why must service operations return HTTPResponse in EK9?)

How to fix it

  1. Return HTTPResponse or compatible type
  2. Wrap data in HTTPResponse constructor

Common causes

  • Returning raw data type instead of HTTPResponse
  • Missing HTTPResponse wrapper

See also

  • E07750: service method wrong return type (this error)
  • E07800: service method missing return

Examples

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

Fails with E07750: Web Service return type must be compatible with HTTPResponse

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

    Numbers for :/numbers open

      //A service method answers with an HTTPResponse
      count() as GET for :/count
        <- total as Integer: 42

Fixed: Return an HTTPResponse carrying the value

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

    Numbers for :/numbers open

      count() as GET for :/count
        <- response as HTTPResponse: TextResponse($42)

Questions and answers

These Q&A entries show E07750 and its fix:

Found a problem?

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