E07680: URI with place holder variable not supported in this context

Category: E07xxx Full resolution · Reported in phase: SYMBOL_DEFINITION · Classification: SERVICE_URI_WITH_VARS_NOT_SUPPORTED · All error codes

What went wrong

A service's own URI holds a path variable ('{region}'). The service URI is fixed: it is where the service is mounted. Path variables belong in the URI of a METHOD (or operator) of the service, where each is bound to a parameter.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 945 (How do HTTP verbs, URI path variables, and parameter q...)

How to fix it

  1. Remove the variable from the service's URI
  2. Put it in the method's URI instead ('byRegion() as GET for :/{region}/{id}') and take it as a parameter of the same name

The [EXAMPLE] section below shows a service mounted at ':/addresses/{region}', and the same variable moved into the method's URI.

Common causes

  • Treating the service URI as a route prefix that can capture values
  • Moving a route from another framework where the controller path takes variables

See also

  • E07680: a path variable in the service's own URI (this error)
  • E07700: invalid path parameter format

Examples

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

Fails with E07680: URI with place holder variable not supported in this context

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

    //The service's own URI is fixed
    Addresses for :/addresses/{region} open

      byId() as GET for :/{id}
        -> id as String
        <- response as HTTPResponse: TextResponse(`address ${id}`)

Fixed: Keep the service URI fixed; put variables in the methods

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

      //Variables go in the method's URI
      byRegion() as GET for :/{region}/{id}
        ->
          region as String
          id as String
        <- response as HTTPResponse: TextResponse(`${region} ${id}`)