Show Users

Add the standard HTTP method, GET, for the User model in the API.

Define the show action

We will define the show action by simply adding the action to our controllers in app/controllers/api/v1/users_controller.rb. The code for the show function is as follows:

Press + to interact
class Api::V1::UsersController < ApplicationController
# GET /users/1
def show
render json: User.find(params[:id])
end
end

Add test

There are two things we want to test for an API:

  • The JSON structure returned by the server.
  • The HTTP
...