-
-
Save kimat/6a94ddec0569a8226a2f97b6f250b03e to your computer and use it in GitHub Desktop.
simple HTTP request testing using net/http and a JSON POST payload | Update: I guess I might start updating this again. I am pretty fickle.
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
#! usr/bin/ruby | |
require 'uri' | |
require 'net/http' | |
require 'json' | |
def getRequest(url) | |
uri = URI.parse(url) | |
http = Net::HTTP.new(uri.host, uri.port) | |
request = Net::HTTP::Get.new(uri.request_uri) | |
request["Accept"] = "application/json" | |
return http.request(request) | |
end | |
def deleteRequest(url) | |
uri = URI.parse(url) | |
http = Net::HTTP.new(uri.host, uri.port) | |
request = Net::HTTP::Delete.new(uri.request_uri) | |
request["Accept"] = "application/json" | |
return http.request(request) | |
end | |
def putRequest(url, payload) | |
uri = URI.parse(url) | |
http = Net::HTTP.new(uri.host, uri.port) | |
request = Net::HTTP::Put.new(uri.request_uri) | |
request["Accept"] = "application/json" | |
request.content_type = "application/json" | |
request.body = payload | |
return http.request(request) | |
end | |
def postRequest(url, payload) | |
uri = URI.parse(url) | |
http = Net::HTTP.new(uri.host, uri.port) | |
request = Net::HTTP::Post.new(uri.request_uri) | |
request["Accept"] = "application/json" | |
request.content_type = "application/json" | |
request.body = payload | |
return http.request(request) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment