Class: RnStack::ApiController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rn_stack/api_controller.rb

Instance Method Summary collapse

Instance Method Details

#handleObject



5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/rn_stack/api_controller.rb', line 5

def handle
  # Dynamically load and call the API handler
  # e.g., app/api/users.rb -> constant Users
  handler_class = params[:api_path].camelize.constantize
  render json: handler_class.call(request)
rescue NameError => e
  render json: { error: "Handler not found", details: e.message }, status: :not_found
rescue StandardError => e
  render json: { error: "API Error", details: e.message }, status: :internal_server_error
end