Skip to main content
Version: v3.0

Routes

Routes for Rhino models listed as resources in config/rhino.rb are automatically generated. The routes are based on the model name and the owner of the model. The routes are generated for the standard CRUD actions except for globally owned models which only have the index and show actions. The base scope for the API routes is /api.

Adding and Removing specific API routes

Specific API routes for a model can be removed with Rhino configuration directives. The only and except options can be used to specify which routes to include or exclude.

class Blog < ApplicationRecord
belongs_to :user

rhino_owner_base
rhino_references %i[user]
# Only index route will be available
rhino_routing only: [:index]
end
class Blog < ApplicationRecord
belongs_to :user

rhino_owner_base
rhino_references %i[user]
# All routes except destroy will be available
rhino_routing except: [:destroy]
end

Adding custom API routes

Custom API routes can be added to the Rhino API by adding them to the config/routes.rb file. The routes can be added in the standard Rails way.

config/routes.rb
Rails.application.routes.draw do
devise_for :admin_users, ActiveAdmin::Devise.config

# We introspect the models to create the admin interface
# https://github.com/activeadmin/activeadmin/issues/783#issuecomment-244587442
ActiveAdmin.routes(self) rescue ActiveAdmin::DatabaseHitDuringLoad

scope Rhino.namespace do
get 'api/mycustom_endpoint', to: 'mycustomcontroller#index'
end

constraints lambda { |req| !req.path.starts_with?("/api/") && !req.path.starts_with?("/rails/") && !req.path.starts_with?("/jobs")} do
match "*path", to: "frontend#root", via: :get
end
root to: "frontend#root", via: :get
end
end

Changing the base API scope

The namespace configuration option can be used to change the base scope for the API routes. For example, setting config.namespace = :my_api would change the base scope for the API routes to /my_api.

config/rhino.rb
Rhino.setup do |config|
# ==> Owner configuration
# The auth owner class
# config.auth_owner = 'User'

# The base owner class
# config.base_owner = "Organization"

# ==> Resource Configuration

# Include Rhino::Resource::ActiveRecordExtension by default
# config.auto_include_active_record = true

# The root path for the api ie '/api'
config.namespace = :my_api

# Authentication
# config.allow_signup = true

# The list of resources exposed in the API
config.resources += ["User"]
end