{"id":13906183,"url":"https://github.com/augustl/net-http-cheat-sheet","last_synced_at":"2026-03-03T16:42:38.477Z","repository":{"id":775164,"uuid":"462071","full_name":"augustl/net-http-cheat-sheet","owner":"augustl","description":"A collection of Ruby Net::HTTP examples.","archived":false,"fork":false,"pushed_at":"2019-04-03T04:53:58.000Z","size":20,"stargazers_count":1149,"open_issues_count":0,"forks_count":163,"subscribers_count":42,"default_branch":"master","last_synced_at":"2025-02-24T08:09:14.054Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/augustl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-01-07T08:42:55.000Z","updated_at":"2025-02-23T12:15:44.000Z","dependencies_parsed_at":"2022-08-06T10:00:50.602Z","dependency_job_id":null,"html_url":"https://github.com/augustl/net-http-cheat-sheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustl%2Fnet-http-cheat-sheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustl%2Fnet-http-cheat-sheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustl%2Fnet-http-cheat-sheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustl%2Fnet-http-cheat-sheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/augustl","download_url":"https://codeload.github.com/augustl/net-http-cheat-sheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241256545,"owners_count":19935074,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T23:01:30.841Z","updated_at":"2025-11-24T19:11:45.137Z","avatar_url":"https://github.com/augustl.png","language":"Ruby","readme":"# Ruby `Net::HTTP` cheat sheet\n\nA bunch of examples of various use cases, implemented with Ruby's `Net::HTTP` library.\n\n# Alternatives to `Net::HTTP`\n\nThis cheat sheet was created many years ago, when invoking `Net::HTTP` directly was common. These days, there are better alternatives around, with much nicer APIs.\n\nCompare multipart file uploads with `Net::HTTP`:\n\n```ruby\nBOUNDARY = \"AaB03x\"\n\nuri = URI.parse(\"http://something.com/uploads\")\nfile = \"/path/to/your/testfile.txt\"\n\npost_body = []\npost_body \u003c\u003c \"--#{BOUNDARY}\\r\\n\"\npost_body \u003c\u003c \"Content-Disposition: form-data; name=\\\"datafile\\\"; filename=\\\"#{File.basename(file)}\\\"\\r\\n\"\npost_body \u003c\u003c \"Content-Type: text/plain\\r\\n\"\npost_body \u003c\u003c \"\\r\\n\"\npost_body \u003c\u003c File.read(file)\npost_body \u003c\u003c \"\\r\\n--#{BOUNDARY}--\\r\\n\"\n\nhttp = Net::HTTP.new(uri.host, uri.port)\nrequest = Net::HTTP::Post.new(uri.request_uri)\nrequest.body = post_body.join\nrequest[\"Content-Type\"] = \"multipart/form-data, boundary=#{BOUNDARY}\"\n\nhttp.request(request)\n```\n\nAnd file uploads with RestClient - just a single line, and no shoddy manual string concatenation:\n\n```ruby\nRestClient.post '/data', :myfile =\u003e File.new(\"/path/to/image.jpg\", 'rb')\n```\n    \nCheck out RestClient! https://github.com/rest-client/rest-client\n","funding_links":[],"categories":["Ruby","Programming Languages"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faugustl%2Fnet-http-cheat-sheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faugustl%2Fnet-http-cheat-sheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faugustl%2Fnet-http-cheat-sheet/lists"}