How can find domain name in Grape::API

498 views Asked by At

I am not able to fetch request object in Grape::API, My method is

module Artical

module Railsapp module V1 class Articleapi < Grape::API include Railsapp::V1::Defaults

  resource :articleapi do
    desc "Return all article"

    get "", root: :articles do
        error!({:error_message => "Please provide a article id."}, 422)
    end

    desc "Return a acticle"

    params do
      requires :id, type: String, desc: "ID of the photo"
    end

    get ":id", root: "photo" do

      @Artical = Contents.where(id: params[:id],content_type: 'Article').first

      if @Artical.present?
        error!({:success_message => "Record found",:result => @Artical }, 300)
      else
        error!({:error_message => "Record Could not found"}, 422)
      end
      # Photos.where(:id =>  @id).update_all(publish_status: @status_value)
    end
  end
1

There are 1 answers

0
Hridya On

In any grape endpoint you can access the request object as "request". The request object has many methods available to access its various parameters.

For example: If you want to access the path details of a request then :

request.path_info

will give the path details of the current request.If you want to know various methods available for request object, just print and check :

request.methods