How must path variable counts match parameters in EK9 services?

← Web Services · Ref: Q946

EK9 validates service method signatures for path consistency:

1. PATH PARAM COUNT MUST MATCH (E07730)

The number of {variables} in the URI must equal the number of parameters declared on the method.

  findItem() as GET for :/{catId}/{itemId}
    -> catId as Integer
    -> itemId as Integer

Two path variables, two parameters — correct.

2. HTTPREQUEST RULES (E07770, E07780)

HTTPRequest can only be used with :=: REQUEST binding, not as a path/query parameter. At most one HTTPRequest parameter per method.

See Q657 for URI mapping. See Q846 for parameter type rules. See Q868 for path parameter types.

Example

defines module qa.services.path.matching

  defines constant

    JSON_CONTENT <- "application/json"

  defines class

    <?-
      Models a catalog item found by category and item identifiers.
      Demonstrates how multi-segment path variables map to parameters.
    -?>
    CatalogItem
      categoryId as Integer: 0
      itemId as Integer: 0
      contentKind as String: JSON_CONTENT

      CatalogItem()
        ->
          givenCategoryId as Integer
          givenItemId as Integer
        this.categoryId :=: givenCategoryId
        this.itemId :=: givenItemId

      categoryId()
        <- rtn as Integer: Integer(categoryId)

      itemId()
        <- rtn as Integer: Integer(itemId)

      contentKind()
        <- rtn as String: String(contentKind)

      toJson()
        <- rtn as String: `{"cat": ${categoryId}, "item": ${itemId}}`

      operator $ as pure
        <- rtn as String: `CatalogItem[${categoryId}, ${itemId}]`
      operator #^ as pure
        <- rtn as String: $this
      default operator ?

    <?-
      Simulates a catalog endpoint with multi-segment path binding.
      In real services: GET /catalog/{catId}/{itemId} requires two parameters.
      The compiler validates path variable count matches parameter count (E07730).
    -?>
    CatalogEndpoint

      findItem()
        ->
          catId as Integer
          itemId as Integer
        <- rtn as CatalogItem: CatalogItem(catId, itemId)

      operator $ as pure
        <- rtn as String: "CatalogEndpoint"
      operator #^ as pure
        <- rtn as String: $this
      default operator ?

  defines program

    ServicePathMatchingDemo()
      stdout <- Stdout()
      endpoint <- CatalogEndpoint()
      catalogResult <- endpoint.findItem(10, 25)

      stdout.println("Path matching rules:")
      stdout.println("  URI variables must match parameter count")
      stdout.println("  GET /catalog/{catId}/{itemId} -> 2 params")
      stdout.println(catalogResult.toJson())
Other ways to ask this
  • What triggers E07730 SERVICE_PATH_PARAM_COUNT_MISMATCH?
  • What triggers E07770 SERVICE_HTTPREQUEST_ONLY_WITH_REQUEST?
  • What triggers E07780 SERVICE_HTTPREQUEST_AT_MOST_ONE?
  • How do I use HTTPRequest in a service method?

Coming from another language?

Java Spring: @PathVariable count must match. Python Flask: <param> count must match function args. Go: manual extraction from URL. EK9: compile-time validation that URI variable count matches parameter count.

Keywords: path, match, parameter, count, E07770, HTTPRequest, variable, E07730, E07780, service