RailsRanger

RailsRanger

new RailsRanger(options)

RailsRanger object constructor

Source:
Parameters:
Name Type Description
options object

Configurations of the new RailsRanger instance

Name Type Description
transformData boolean

Sets the response/request data transformations on/off

axios object

Configurations to be be handed down to Axios

Methods

create(resource, params) → {Promise}

Makes a POST request to the create path of the given resource

Source:
Parameters:
Name Type Description
resource string

The base path of the request

params object

The parameters to be injected in the path as query

Returns:
Type:
Promise
Example
const api = new RailsRanger
api.create('users', { email: 'john@doe.com', password: 123456 })
//=> POST request to '/users' path with the { email: 'john@doe.com', password: 123456 } parameters

delete(path, params) → {Promise}

Makes a DELETE request to the given path with the given parameters

Source:
Parameters:
Name Type Description
path string

The base path of the request

params object

The parameters to be injected in the path (as query or replacing path segments)

Returns:
Type:
Promise
Example
const api = new RailsRanger
api.delete('/users/:id', { id: 1, flag: true })
//=> DELETE request to '/users/1?flag=true' path

destroy(resource, params) → {Promise}

Makes a DELETE request to the destroy path of the given resource

Source:
Parameters:
Name Type Description
resource string

The base path of the request

params object

The parameters to be injected in the path as query

Name Type Description
id number | string

The id of the resource

Returns:
Type:
Promise
Example
const api = new RailsRanger
api.destroy('users', { id: 1, flag: true })
//=> DELETE request to '/users/1?flag=true' path

edit(resource, params) → {Promise}

Makes a GET request to the edit path of the given resource

Source:
Parameters:
Name Type Description
resource string

The base path of the request

params object

The parameters to be injected in the path as query

Name Type Description
id number | string

The id of the resource

Returns:
Type:
Promise
Example
const api = new RailsRanger
api.edit('users', { id: 1, flag: true })
//=> GET request to '/users/1/edit?flag=true' path

get(path, params) → {Promise}

Makes a GET request to the given path with the given parameters

Source:
Parameters:
Name Type Description
path string

The base path of the request

params object

The parameters to be injected in the path (as query or replacing path segments)

Returns:
Type:
Promise
Example
const api = new RailsRanger
api.get('/users/:id', { id: 1, flag: true })
//=> GET request to '/users/1?flag=true' path

list(resource, params) → {Promise}

Makes a GET request to the index path of the given resource

Source:
Parameters:
Name Type Description
resource string

The base path of the request

params object

The parameters to be injected in the path as query

Returns:
Type:
Promise
Example
const api = new RailsRanger
api.list('users', { flag: true })
//=> GET request to '/users?flag=true' path

namespace(namespace, params)

Defines a namespace to be used in the next request 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 api = new RailsRanger
api.namespace('admin/:type', { type: 'super' }).list('blogPosts')
//=> GET request to '/admin/super/blog_posts' path

new(resource, params) → {Promise}

Makes a GET request to the new path of the given resource

Source:
Parameters:
Name Type Description
resource string

The base path of the request

params object

The parameters to be injected in the path as query

Returns:
Type:
Promise
Example
const api = new RailsRanger
api.new('users', { flag: true })
//=> GET request to '/users/new?flag=true' path

patch(path, params) → {Promise}

Makes a PATCH request to the given path with the given parameters

Source:
Parameters:
Name Type Description
path string

The base path of the request

params object

The parameters to be injected in the path or sent in the request payload

Returns:
Type:
Promise
Example
const api = new RailsRanger
api.patch('/users/:id', { id: 1, flag: true })
//=> PATCH request to '/users/1' path with { flag: true } parameters

post(path, params) → {Promise}

Makes a POST request to the given path with the given parameters

Source:
Parameters:
Name Type Description
path string

The base path of the request

params object

The parameters to be injected in the path or sent in the request payload

Returns:
Type:
Promise
Example
const api = new RailsRanger
api.post('/users/:id', { id: 1, flag: true })
//=> POST request to '/users/1' path with { flag: true } parameters

put(path, params) → {Promise}

Makes a PUT request to the given path with the given parameters

Source:
Parameters:
Name Type Description
path string

The base path of the request

params object

The parameters to be injected in the path or sent in the request payload

Returns:
Type:
Promise
Example
const api = new RailsRanger
api.put('/users/:id', { id: 1, flag: true })
//=> PUT request to '/users/1' path with { flag: true } parameters

resource(resource, id)

Defines a namespace to be used in the next request 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 api = new RailsRanger
api.resource('users', 1).list('blogPosts')
//=> GET request to '/users/1/blog_posts' path

show(resource, params) → {Promise}

Makes a GET request to the show path of the given resource

Source:
Parameters:
Name Type Description
resource string

The base path of the request

params object

The parameters to be injected in the path as query

Name Type Description
id number | string

The id of the resource

Returns:
Type:
Promise
Example
const api = new RailsRanger
api.show('users', { id: 1, flag: true })
//=> GET request to '/users/1?flag=true' path

update(resource, params) → {Promise}

Makes a PATCH request to the update path of the given resource

Source:
Parameters:
Name Type Description
resource string

The base path of the request

params object

The parameters to be injected in the path as query

Name Type Description
id number | string

The id of the resource

Returns:
Type:
Promise
Example
const api = new RailsRanger
api.update('users', { id: 1, email: 'elton@doe.com' })
//=> PATCH request to '/users/1' path with the { email: 'elton@doe.com' } parameters