Why can't I use HTTPRequest as a path parameter type in EK9 services?

← Web Services · Ref: Q868

HTTPRequest can only be used with :=: REQUEST binding. Using HTTPRequest as a PATH parameter type triggers E07790 because path parameters are parsed from URI segments — they must be simple types like Integer or String.

CORRECT PATTERN

  findById() as GET for :/{userId}
    -> userId as Integer

Integer is a valid path parameter type.

INCORRECT PATTERN

  findById() as GET for :/{userId}
    -> userId as HTTPRequest

HTTPRequest cannot be bound to a PATH segment. Use :=: REQUEST binding if you need the full request.

VALID PATH PARAMETER TYPES

Integer, String, Date, Duration, DateTime, Time, Millisecond.

See Q846 for parameter type rules. See Q202 for parameter binding.

Example

defines module qa.webdeep.service.request.param.type

  defines constant

    JSON_RESPONSE <- "application/json"

  defines service

    <?-
      Service with valid Integer path parameter.
      Path parameters must be simple parseable types.
    -?>
    AccountService :/accounts open

      findById() as GET for :/{userId}
        -> userId as Integer
        <- response as HTTPResponse: (capturedId: userId) with trait HTTPResponse
          override content()
            <- rtn as String: `{"userId": ${capturedId}}`
          override status() as pure
            <- rtn as Integer: 200
          override contentType() as pure
            <- rtn as String: JSON_RESPONSE
          override cacheControl() as pure
            <- rtn as String: "no-cache"
          override contentLanguage() as pure
            <- rtn as String: "en"
          default operator ?

  defines application

    AccountApp
      register AccountService()

  defines program

    ServiceParamTypeDemo()
      stdout <- Stdout()
      stdout.println("Valid path param types: Integer, String, Date, Time")
      stdout.println("Invalid: HTTPRequest (use :=: REQUEST binding instead)")

Common mistakes

E07790 — HTTPRequest cannot be used as a path parameter type. Path parameters are parsed from URI segments and must be simple types like Integer or String. Use :=: REQUEST binding for HTTPRequest. See ek9 -h E07790 for details.

Incorrect:

        -> userId as HTTPRequest

Correct:

        -> userId as Integer
Other ways to ask this
  • What triggers E07790 SERVICE_INCOMPATIBLE_PARAM_TYPE_NON_REQUEST?
  • When is HTTPRequest invalid as a service parameter type?
  • How do I correctly bind service path parameters?

Coming from another language?

Java Spring: @PathVariable binds to any type with a converter. C# ASP.NET: model binding to complex types. Go: manual string parsing. Python Flask: parameter converters at runtime. EK9: compile-time restriction prevents HTTPRequest from being used as a path or query parameter.

Keywords: E07790, path, service, HTTPRequest, binding, parameter, type, Integer