Last active
December 25, 2019 01:40
-
-
Save linqueta/badce27997df7a594bf0e87db858e225 to your computer and use it in GitHub Desktop.
Adding a header into the request using before hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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