A Wrapper around Net/HTTP which allows you to perform HTTP Requests in a simple way.
Installation¶ ↑
gem install http-requestor
Usage¶ ↑
Initialize a domain, and send request to multiple paths¶ ↑
http = HTTP::Requestor.new("http://www.mydomain.com") # This will initialize the HTTP::Requestor class get_request = http.get(path, parameters, headers) post_request = http.post(path, parameters, headers) put_request = http.put(path, parameters, headers) delete_request = http.delete(path, parameters, headers) # path => for example: "/some_path" # parameters => this is an optional parameter, if you want to send some parameters alongwith the request # headers => this is also an optional parameter, you can pass a hash with stringified keys
Get a response right away ¶ ↑
HTTP::Requestor.request(domain, request_type, path, parameters, headers) # domain => for example: "http://www.some_domain.com" # request_type => GET|POST|PUT|DELETE # path => for example: "/some_path" # parameters => this is an optional parameter, if you want to send some parameters alongwith the request # headers => this is also an optional parameter, you can pass a hash with stringified keys
OR you can do it the other way
HTTP::Requestor.request_with_url(url, request_type, data, headers) # url => for example: "http://www.some_domain.com/some_path_value" # request_type => GET|POST|PUT|DELETE # parameters => this is an optional parameter, if you want to send some parameters alongwith the request # headers => this is also an optional parameter, you can pass a hash with stringified keys
HTTP Basic Authentication¶ ↑
HTTP::Requestor.send_basic_auth_request(url, username, password) # url => for example: "http://www.some_domain.com/some_path_value" only GET URL's supported currently # username => basic_auth_username # password => basic_auth_password
Multipart Form Post¶ ↑
uri = "http://some_domain/somepath" data = {:file => File.open("testfile.txt")} response = HTTP::Requestor.multipart_request(uri, "post | put", data) # If you already have the instance of HTTP::Requestor class then you can upload files as follows: http = HTTP::Requestor.new("http://www.mydomain.com") response = http.post_multipart(some_path, {:file => File.open("testfile.txt")}) response = http.put_multipart(some_path, {:file => File.open("testfile.txt")})
More HTTP Verbs¶ ↑
You can also use other HTTP Verbs such as OPTIONS, PATCH, MOVE, HEAD, TRACE * By instantiating the HTTP::Requestor class http = HTTP::Requestor.new("http://www.mydomain.com") http.options(path, parameters, headers) http.patch(path, parameters, headers) http.move(path, parameters, headers) http.head(path, parameters, headers) http.trace(path, parameters, headers) * Directly calling the request method HTTP::Requestor.request(domain, request_type, path, parameters, headers) # where request type can be any value within GET, POST, PUT, DELETE, OPTIONS, PATCH, MOVE, HEAD, TRACE
Issues and Suggestions¶ ↑
Please report all the issues in the Github Issues Page, suggestions are also welcome. You can also mail me at rohit0981989[at]gmailcom for the same.