N01
Error
Requests
N01 — A path that names no parameter
An endpoint's path names its parameters, at "users/{id}": each {name} is filled by the parameter of that name, and one that no parameter fills would be sent as written. A parameter has one place — the path, a header or a cookie.
What the compiler said
error[N01]: `Backend.user` is at `users/{id}`, and no parameter fills `{id}` --> src/App.wf:4:5 | 4 | get user(userId: String) at "users/{id}" -> User! | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: Name a parameter `id`; it takes `userId` = docs: https://webfluent.monzeromer.dev/errors/N01
The fix
Broken
type User { id: String, name: String }
api Backend(base: "/api") {
get user(userId: String) at "users/{id}" -> User!
}
page P(path: "/", title: "T", description: "D") {
resource user = Backend.user("7")
Heading("Profile").h1
match user {
.loaded(u) { Text(u.name) }
else { Spinner }
}
}
Fixed
type User { id: String, name: String }
api Backend(base: "/api") {
get user(id: String) at "users/{id}" -> User!
}
page P(path: "/", title: "T", description: "D") {
resource user = Backend.user("7")
Heading("Profile").h1
match user {
.loaded(u) { Text(u.name) }
else { Spinner }
}
}
Name the parameter as the path does, or write the path with the parameter's name. A parameter meant for a header or a cookie is taken out of the path.
Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).
Why this rule exists
Error.
An endpoint's path names the parameters that go in it: at "users/{id}"
is sent as users/7 when the call passes id: "7". A {name} that no
parameter of the endpoint fills would be sent as it is written, braces and
all, and the server would answer a path it does not have.
A parameter also has one place. One the path names goes in the path; it cannot be sent as a header or a cookie too.
lints cannot lower it: it would ship a broken page.