Challenge - 5 Problems
Rails API Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2: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?
Attempts:
2 left
💡 Hint
Think about what an API-only app does not need compared to a full web app.
✗ Incorrect
API-only apps do not use sessions or cookies by default, so their middleware is excluded. Other middleware like logging and request ID remain.
📝 Syntax
intermediate2:00remaining
How to generate a new Rails API-only app?
Which command correctly creates a new Rails API-only application named
my_api?Attempts:
2 left
💡 Hint
The flag is short and starts with two dashes.
✗ Incorrect
The correct flag to create an API-only Rails app is --api.
❓ state_output
advanced2: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
Attempts:
2 left
💡 Hint
API-only apps focus on data exchange formats.
✗ Incorrect
Rails API-only apps default to JSON responses for data rendering.
🔧 Debug
advanced2: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
Attempts:
2 left
💡 Hint
Think about what Rails disables by default in API-only mode.
✗ Incorrect
CSRF protection is disabled by default in API-only apps because APIs usually use tokens or other auth methods. Enabling it without tokens causes errors.
🧠 Conceptual
expert2: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?Attempts:
2 left
💡 Hint
Think about what an API-only app does NOT include.
✗ Incorrect
API-only mode creates a slim backend focused on serving JSON data, skipping views, assets, and session middleware.