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 <- response as HTTPResponse: ...
Two path variables, two parameters — correct.
2. HTTPREQUEST RULES (E07770, E07780, E07790)
A parameter bound with :=: REQUEST must be typed HTTPRequest (E07770), and HTTPRequest used as a path/query/header parameter instead is E07790. An HTTPRequest parameter must be the ONLY parameter of the method (E07780).
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_HTTP_PATH_PARAM_COUNT_INVALID?
- What does E07770 report when a REQUEST binding is not typed HTTPRequest?
- What does E07780 report when HTTPRequest sits beside other parameters?
- 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: service, E07730, E07780, match, parameter, E07790, path, HTTPRequest, variable, count, E07770