view raw
k9b k9b - 11 months ago 101
Ruby Question

Token authentication

Simple code

require 'net/http'

url = URI.parse('get json/other data here [link]')
req =
res = Net::HTTP.start(, url.port) {|http|
puts res.body

Just wondering how to put an authentication token in php cURL i do it like this

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer xxx')); //Bearer token for authentication

Wondering how to do it for Ruby.


You can simply add header:

req =
req['Authorization'] = "Bearer xxx"

or shorter:

request =, {'Authorization' => 'Bearer vF9dft4qmT'})