Skip to content

Instantly share code, notes, and snippets.

@linqueta
Last active December 25, 2019 01:40
Show Gist options
  • Save linqueta/badce27997df7a594bf0e87db858e225 to your computer and use it in GitHub Desktop.
Save linqueta/badce27997df7a594bf0e87db858e225 to your computer and use it in GitHub Desktop.
Adding a header into the request using before hook
require 'eezee'
require 'initializer'
require 'character'
RickMorty::Character.find!(1).body
# "INFO -- request: GET https://rickandmortyapi.com/api/character/1"
# "INFO -- request: HEADERS: {\"X-Application-Name\":\"MyTestApp\"}"
# "INFO -- request: PAYLOAD: {}"
# "INFO -- response: SUCCESS: true"
# "INFO -- response: TIMEOUT: false"
# "INFO -- response: CODE: 200"
# "INFO -- response: BODY: {\"id\":1,\"name\":\...
# => {:id=>1, :name=>"Rick Sanchez", :status=>"Alive", :speci...
module RickMorty; end
module RickMorty::Character
extend Eezee::Client
eezee_service :rick_and_morty_api
eezee_request_options path: 'character/:character_id'
module_function
def find!(id)
get(
params: { character_id: id },
before: ->(req) { req.headers.merge!('X-Application-Name': 'MyTestApp') }
)
end
end
Eezee.configure do |config|
config.add_service :rick_and_morty_api,
url: 'rickandmortyapi.com/api',
protocol: :https,
raise_error: true,
logger: true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment