[{"data":1,"prerenderedAt":78},["Reactive",2],{"/samples/ruby/nethttp":3,"related:FGTOj3JOoM":60},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":11,"link":12,"body":13,"_type":55,"_id":56,"_source":57,"_file":58,"_extension":59},"/samples/ruby/nethttp","ruby",false,"","Nethttp","Net::HTTP is a built-in HTTP client library for Ruby that provides basic functionality for making HTTP requests and handling responses. It is part of the Ruby standard library and offers a simple API for sending requests and receiving responses from web servers.","Ruby","Net::HTTP","https://ruby-doc.org/stdlib-2.7.0/libdoc/net/http/rdoc/Net/HTTP.html",{"type":14,"children":15,"toc":52},"root",[16,31,43],{"type":17,"tag":18,"props":19,"children":20},"element","p",{},[21,29],{"type":17,"tag":22,"props":23,"children":26},"a",{"href":12,"rel":24},[25],"nofollow",[27],{"type":28,"value":11},"text",{"type":28,"value":30}," is a built-in HTTP client library for Ruby that provides basic functionality for making HTTP requests and handling responses. It is part of the Ruby standard library and offers a simple API for sending requests and receiving responses from web servers.",{"type":17,"tag":32,"props":33,"children":37},"pre",{"className":34,"code":36,"language":5,"meta":7},[35],"language-ruby","require 'net/http'\nrequire 'uri'\nrequire 'json'\n\ndef convert(api_key, params, endpoint = 'pdf')\n  # Ensure the endpoint is valid\n  unless %w[pdf png jpg webp].include?(endpoint)\n    raise ArgumentError, 'Invalid endpoint specified'\n  end\n\n  # Set the API URL\n  url = URI(\"https://api.pdfshift.io/v3/convert/#{endpoint}\")\n\n  # Create a Net::HTTP instance\n  http = Net::HTTP.new(url.host, url.port)\n  http.use_ssl = true\n\n  # Create the request\n  request = Net::HTTP::Post.new(url)\n  request['Content-Type'] = 'application/json'\n  request['X-API-Key'] = api_key\n  request.body = params.to_json\n\n  # Send the request and handle the response\n  response = http.request(request)\n\n  # Check for successful response\n  unless response.is_a?(Net::HTTPSuccess)\n    raise \"Request failed with status code #{response.code}: #{response.body}\"\n  end\n\n  # Return the response based on the presence of filename or webhook\n  response_body.key?('filename') || response_body.key?('webhook') ? JSON.parse(response.body) : response.body\nend\n",[38],{"type":17,"tag":39,"props":40,"children":41},"code",{"__ignoreMap":7},[42],{"type":28,"value":36},{"type":17,"tag":32,"props":44,"children":47},{"className":45,"code":46,"language":5,"meta":7},[35],"begin\n  result = convert('sk_XXXXXXXXXXXXXX', {'source' => 'https://en.wikipedia.org/wiki/REST'})\n  puts result\nrescue StandardError => e\n  puts \"Error: #{e.message}\"\nend\n",[48],{"type":17,"tag":39,"props":49,"children":50},{"__ignoreMap":7},[51],{"type":28,"value":46},{"title":7,"searchDepth":53,"depth":53,"links":54},2,[],"markdown","content:samples:ruby:nethttp.md","content","samples/ruby/nethttp.md","md",[61,65,69,70,74],{"_path":62,"language":10,"library":63,"_id":64},"/samples/ruby/faraday","Faraday","content:samples:ruby:faraday.md",{"_path":66,"language":10,"library":67,"_id":68},"/samples/ruby/httpparty","HttpParty","content:samples:ruby:httpparty.md",{"_path":4,"language":10,"library":11,"_id":56},{"_path":71,"language":10,"library":72,"_id":73},"/samples/ruby/restclient","RestClient","content:samples:ruby:restclient.md",{"_path":75,"language":10,"library":76,"_id":77},"/samples/ruby/typhoeus","Typhoeus","content:samples:ruby:typhoeus.md",1785426823487]