sanitized path and query parameters in a web service

The complete source of sanitized_service.ek9, compiled by the EK9 compiler. Shown on sanitized.html.

#!ek9
defines module site.sanitized.service

  defines function

    userResponse() as pure
      -> detail as String
      <- response as HTTPResponse: (detail) with trait of HTTPResponse
        override content()
          <- rtn as Bytes: Bytes().withUtf8(detail)
        override status() as pure
          <- rtn as Integer: 200
        override contentType() as pure
          <- rtn as String: "text/plain"
        override cacheControl() as pure
          <- rtn as String: "no-cache"
        override contentLanguage() as pure
          <- rtn as String: "en"
        default operator ?

  defines service

    UserService for :/users open

      getUser() as GET for :/{userId}
        -> userId as sanitized String :=: PATH
        <- response as HTTPResponse: userResponse(userId)
        //userId is sanitized before any of this method's code runs

      searchUsers() as GET for :/search
        -> query as sanitized String :=: QUERY "query"
        <- response as HTTPResponse: userResponse(query)
        //and so is the query parameter

Download sanitized_service.ek9