Methods
create(resource, params) → {Promise}
Returns a path and params to the create action of a given resource
- Source:
Parameters:
Name | Type | Description |
---|---|---|
resource |
string
|
A resource name |
params |
object
|
Any parameters for the request |
Returns:
- Type:
-
Promise
Example
const routes = new RouteBuilder
routes.create('users', { email: 'john@doe.com' })
//=> { path: '/users', params: { email: 'john@doe.com' } }
delete(path, params) → {Promise}
Returns a path and params to the specified DELETE request
- Source:
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
path |
string
|
A path for the request |
||||||
params |
object
|
Any parameters for the request
|
Returns:
- Type:
-
Promise
Example
const routes = new RouteBuilder
routes.delete('users', { id: 1 })
//=> { path: '/users?id=1', params: {} }
destroy(resource, params) → {Promise}
Returns a path and params to the destroy action of a given resource
- Source:
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
resource |
string
|
A resource name |
||||||
params |
object
|
Any parameters for the request
|
Returns:
- Type:
-
Promise
Example
const routes = new RouteBuilder
routes.destroy('users', { id: 1 })
//=> { path: '/users/1', params: {} }
edit(resource, params) → {Promise}
Returns a path and params to the edit action of a given resource
- Source:
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
resource |
string
|
A resource name |
||||||
params |
object
|
Any parameters for the request
|
Returns:
- Type:
-
Promise
Example
const routes = new RouteBuilder
routes.edit('users', { id: 1 })
//=> { path: '/users/1', params: {} }
get(path, params) → {Promise}
Returns a path and params to the specified GET request
- Source:
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
path |
string
|
A path for the request |
||||||
params |
object
|
Any parameters for the request
|
Returns:
- Type:
-
Promise
Example
const routes = new RouteBuilder
routes.get('users')
//=> { path: '/users', params: {} }
index(resource, params) → {Promise}
Returns a path and params to the index action of a given resource
- Source:
Parameters:
Name | Type | Description |
---|---|---|
resource |
string
|
A resource name |
params |
object
|
Any parameters for the request |
Returns:
- Type:
-
Promise
Example
const routes = new RouteBuilder
routes.index('users')
//=> { path: '/users', params: {} }
namespace(namespace, params)
Defines a namespace to be used in the next route of the chain
- Source:
Parameters:
Name | Type | Description |
---|---|---|
namespace |
string
|
The path fragment to be used as the namespace |
params |
object
|
The parameters to be interpolated into the path, can be left empty |
Example
const routes = new RouteBuilder
routes.namespace('admin').list('blogPosts')
//=> { path: '/admin/blog_posts', params: {} }
new(resource, params) → {Promise}
Returns a path and params to the new action of a given resource
- Source:
Parameters:
Name | Type | Description |
---|---|---|
resource |
string
|
A resource name |
params |
object
|
Any parameters for the request |
Returns:
- Type:
-
Promise
Example
const routes = new RouteBuilder
routes.new('users')
//=> { path: '/users', params: {} }
patch(path, params) → {Promise}
Returns a path and params to the specified PATCH request
- Source:
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
path |
string
|
A path for the request |
||||||
params |
object
|
Any parameters for the request
|
Returns:
- Type:
-
Promise
Example
const routes = new RouteBuilder
routes.patch('users', { id: 1 })
//=> { path: '/users', params: { id: 1 } }
post(path, params) → {Promise}
Returns a path and params to the specified POST request
- Source:
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
path |
string
|
A path for the request |
||||||
params |
object
|
Any parameters for the request
|
Returns:
- Type:
-
Promise
Example
const routes = new RouteBuilder
routes.post('users', { id: 1 })
//=> { path: '/users', params: { id: 1 } }
put(path, params) → {Promise}
Returns a path and params to the specified PUT request
- Source:
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
path |
string
|
A path for the request |
||||||
params |
object
|
Any parameters for the request
|
Returns:
- Type:
-
Promise
Example
const routes = new RouteBuilder
routes.put('users', { id: 1 })
//=> { path: '/users', params: { id: 1 } }
resource(resource, id)
Defines a namespace to be used in the next route of the chain
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
resource |
string
|
the name of the resource to be used as namespace |
|
id |
integer
|
null |
the ID of the resource, can be left empty |
Example
const routes = new RouteBuilder
routes.resource('users', 1).list('blogPosts')
//=> { path: '/users/1/blog_posts', params: {} }
show(resource, params) → {Promise}
Returns a path and params to the show action of a given resource
- Source:
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
resource |
string
|
A resource name |
||||||
params |
object
|
Any parameters for the request
|
Returns:
- Type:
-
Promise
Example
const routes = new RouteBuilder
routes.show('users', { id: 1 })
//=> { path: '/users/1', params: {} }
update(resource, params) → {Promise}
Returns a path and params to the update action of a given resource
- Source:
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
resource |
string
|
A resource name |
||||||
params |
object
|
Any parameters for the request
|
Returns:
- Type:
-
Promise
Example
const routes = new RouteBuilder
routes.update('users', { id: 1, email: 'john@doe.com' })
//=> { path: '/users/1', params: { email: 'john@doe.com' } }