Closed nhunzaker closed 8 years ago
Should
var users = API.namespace('users').route({
posts: {
read() {
path: 'users/:id'
}
}
})
be
var users = API.namespace('users').route({
posts: {
read() {
path: 'users/:user_id/posts'
}
}
})
? That path thing reads funny to me as is.
@mackermedia I had that path wrong with way. It should have been /posts/:id
.
Edit: More in a minute
I'm not sure I understand all of the code updates, but the tests look good :+1:
@mackermedia path
is awkward. The best alternative that I can think of would be a breaking update (now that we have namespaces) to convert the following:
API.route({
posts: {
read() {
path: 'posts/:id'
}
}
})
into
API.namespace('posts').route({
read() {
path: ':id'
}
})
Additionally, we could allow absolute paths to operate against the base URL like:
API.namespace('posts').route({
read() {
path: '/posts/:id'
}
})
I think this feels more intuitive to how relative paths work in the browser. We'd definitely have to ship a 2.0
for this though, and it would break every project using Gangway. Still, the upgrade path would be pretty clear.
Lastly, is namespace
the best name for this?
:+1:
:+1: this is perfect!
This PR should allow for the deep namespacing of routes. For example, the following are now possible:
Additionally:
Nested parameter names for nested routes are singularized, following the convention of Rails. For example:
This will produce the following routes:
API.users.create()
at/users
API.users.read()
at/users/{id?}
API.users.update()
at/users/{id}
API.users.destroy()
at/users/{id}
and
API.users.posts.create()
at/users/{user_id}/posts
API.users.posts.read()
at/users/{user_id}/posts/{id?}
API.users.posts.update()
at/users/{user_id}/posts/{id}
API.users.posts.destroy()
at/users/{user_id}/posts/{id}