Headers
Request headers
Request headers can be set by passing a ruby hash containing keys and values representing header names and values
GET
# GET request with modified headers
RestMan.get(
'http://example.com/resource',
{
Authorization: 'Bearer cT0febFoD5lxAlNAXHo6g'
}
)
POST
# POST request with modified headers
RestMan.post(
'http://example.com/resource',
{
foo: 'bar',
baz: 'qux'
}, {
Authorization: 'Bearer cT0febFoD5lxAlNAXHo6g'
}
)
PUT
# PUT request with modified headers
RestMan.put(
'http://example.com/resource',
{
foo: 'bar',
baz: 'qux'
}, {
Authorization: 'Bearer cT0febFoD5lxAlNAXHo6g'
}
)
PATCH
# PUT request with modified headers
RestMan.patch(
'http://example.com/resource',
{
foo: 'bar',
baz: 'qux'
}, {
Authorization: 'Bearer cT0febFoD5lxAlNAXHo6g'
}
)
DELETE
# DELETE request with modified headers
RestMan.delete(
'http://example.com/resource',
{
Authorization: 'Bearer cT0febFoD5lxAlNAXHo6g'
}
)
HEAD
# HEAD request with modified headers
RestMan.head(
'http://example.com/resource',
{
Authorization: 'Bearer cT0febFoD5lxAlNAXHo6g'
}
)
Request headers customization with underscore symbol
GET
/test
HTTP/1.1
Accept: */*
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Host: example.com
User-Agent: RestMan
HTTP/1.1
200
OK
Content-Type: text/plain
Hello world!
RestMan.get(
"http://example.com/test",
{ "User-Agent" => "RestMan" }
)
# Underscore symbol
RestMan.get(
"http://example.com/test",
{ user_agent: "RestMan" }
)
RestMan::Request.execute(
method: :get,
url: "http://example.com/test",
headers: { "User-Agent" => "RestMan" }
)
# Underscore symbol
RestMan::Request.execute(
method: :get,
url: "http://example.com/test",
headers: { user_agent: "RestMan" }
)
resource = RestMan::Resource.new(
"http://example.com/test",
headers: { "User-Agent" => "RestMan" }
)
resposne = resource.get
# Underscore symbol
resource = RestMan::Resource.new(
"http://example.com/test",
headers: { user_agent: "RestMan" }
)
resposne = resource.get
RestMan doesn't support custom headers currently.
Response headers (processed)
RestMan will parse response header keys to underscore symbol
GET
/test
HTTP/1.1
Accept: */*
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Host: example.com
User-Agent: Mozilla/5.0
HTTP/1.1
200
OK
Content-Type: text/plain
Hello world!
response = RestMan.get "http://example.com/test"
resonse.headers[:content_type] #=> "text/plain"
response = RestMan::Request.execute(
method: :get,
url: "http://example.com/test"
)
resonse.headers[:content_type] #=> "text/plain"
resource = RestMan::Resource.new("http://example.com/test")
resposne = resource.get
resonse.headers[:content_type] #=> "text/plain"
RestMan doesn't support check headers currently.
Response headers (raw)
RestMan offer a way to access raw headers if you don’t like above underscore symbol style
GET
/test
HTTP/1.1
Accept: */*
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Host: example.com
User-Agent: Mozilla/5.0
HTTP/1.1
200
OK
Content-Type: text/plain
Hello world!
response = RestMan.get "http://example.com/test"
resonse.headers["content-type"] #=> "text/plain"
response = RestMan::Request.execute(
method: :get,
url: "http://example.com/test"
)
resonse.headers["content-type"] #=> "text/plain"
resource = RestMan::Resource.new("http://example.com/test")
resposne = resource.get
resonse.headers["content-type"] #=> "text/plain"
RestMan doesn't support check headers currently.