Home > Enterprise >  Ruby on rails - API add status route
Ruby on rails - API add status route

Time:09-14

Im building an API on rails and im new in this framework. I want to add a status route to the API. For example, running in local, if i make a request to endpoint: GET /status (http://localhost:3000/status) it should have to return status code 204, just that.

How can i do it?

I was thinking of creating a model called status and just use the index method, rendering status: :204, but I think there has to be an easier way.

Thanks!

CodePudding user response:

There is no need for a Status model in this example.

Add a new routes to your config/routes.rb:

resource :status, only: [:show] # note the singular `resource` instead `resources`

And add a new controller at app/controllers/statuses_controller.rb (plural here) with this content;

class StatusesController < ApplicationController
  def show
    head :no_content
  end
end
  • Related