0
0
Ruby on Railsframework~20 mins

API-only application setup in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rails API Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the default middleware stack in a Rails API-only app?
In a Rails API-only application, which middleware is excluded by default compared to a full Rails app?
ARequest ID middleware is excluded by default.
BStatic file server middleware is excluded by default.
CSession and cookie middleware are excluded by default.
DLogger middleware is excluded by default.
Attempts:
2 left
💡 Hint
Think about what an API-only app does not need compared to a full web app.
📝 Syntax
intermediate
2:00remaining
How to generate a new Rails API-only app?
Which command correctly creates a new Rails API-only application named my_api?
Arails new my_api --only-api
Brails new my_api --api
Crails new my_api --api-only
Drails new my_api --api_mode
Attempts:
2 left
💡 Hint
The flag is short and starts with two dashes.
state_output
advanced
2:00remaining
What is the default response format in Rails API-only controllers?
Given a Rails API-only controller without explicit format settings, what is the default response format when a client requests data?
Ruby on Rails
class BooksController < ApplicationController
  def index
    render json: { books: ['Ruby', 'Rails'] }
  end
end
APlain text
BXML
CHTML
DJSON
Attempts:
2 left
💡 Hint
API-only apps focus on data exchange formats.
🔧 Debug
advanced
2:00remaining
Why does this API-only app raise a Missing CSRF Token error?
Consider this Rails API-only app controller code:
class PostsController < ApplicationController
  protect_from_forgery with: :exception

  def create
    render json: { status: 'ok' }
  end
end
Why does this cause a CSRF token missing error when posting?
Ruby on Rails
class PostsController < ApplicationController
  protect_from_forgery with: :exception

  def create
    render json: { status: 'ok' }
  end
end
AAPI-only apps disable CSRF protection by default; enabling it causes errors without tokens.
BThe controller is missing a before_action to authenticate the user.
CThe render json call is incorrect and causes the error.
DThe routes file is missing the POST route for create.
Attempts:
2 left
💡 Hint
Think about what Rails disables by default in API-only mode.
🧠 Conceptual
expert
2:00remaining
What is the main reason to choose API-only mode in Rails?
Why would a developer choose to create a Rails application with the --api flag instead of a full Rails app?
ATo build a lightweight backend focused on JSON APIs without views or assets.
BTo enable automatic generation of HTML views and layouts.
CTo create a full-stack app with integrated frontend templates.
DTo include all default middleware for session and cookie management.
Attempts:
2 left
💡 Hint
Think about what an API-only app does NOT include.