Why must all EK9 service methods return HTTPResponse?

← Web Services · Ref: Q845

ALL EK9 service methods must return HTTPResponse. Services are HTTP endpoints — only HTTPResponse can express status codes, headers, content type, and body.

See Q659 for service return types. See Q684 for URI paths.

Example

defines module qa.webservicesdeep.service.return.httpresponse

  defines service

    HealthEndpoint :/health open

      healthCheck() as GET for :/status
        <- response as HTTPResponse: () with trait HTTPResponse
          override content()
            <- rtn as String: `{"status": "healthy"}`
          override status() as pure
            <- rtn as Integer: 200
          override contentType() as pure
            <- rtn as String: "application/json"
          override cacheControl() as pure
            <- rtn as String: "no-cache"
          override contentLanguage() as pure
            <- rtn as String: "en"
          default operator ?

  defines application

    HealthApp
      register HealthEndpoint()

  defines program

    ServiceReturnDemo()
      stdout <- Stdout()
      stdout.println("Service methods must return HTTPResponse")
Other ways to ask this
  • What triggers E07800 SERVICE_MISSING_RETURN?
  • Why can't my service method omit a return type?
  • What return type do EK9 service methods require?

Coming from another language?

Java Spring: controllers return any type. C# ASP.NET: IActionResult or POCO. Go: writes to ResponseWriter. EK9: mandatory HTTPResponse.

Keywords: E07800, HTTPResponse, service, return, endpoint