{"id":13463450,"url":"https://github.com/toland/patron","last_synced_at":"2025-03-25T06:31:59.574Z","repository":{"id":598872,"uuid":"234467","full_name":"toland/patron","owner":"toland","description":"Ruby HTTP client based on libcurl","archived":false,"fork":false,"pushed_at":"2025-02-27T21:59:40.000Z","size":589,"stargazers_count":542,"open_issues_count":8,"forks_count":74,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-20T02:12:50.039Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://toland.github.com/patron/","language":"C","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/toland.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2009-06-23T17:14:12.000Z","updated_at":"2025-02-27T21:58:29.000Z","dependencies_parsed_at":"2024-08-28T15:44:11.189Z","dependency_job_id":"5258d9f3-30d7-4b03-a2bd-fefdb879b6d4","html_url":"https://github.com/toland/patron","commit_stats":{"total_commits":383,"total_committers":53,"mean_commits":7.226415094339623,"dds":0.720626631853786,"last_synced_commit":"f5290598fee51cc56498b5d00d519727c769ddb2"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toland%2Fpatron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toland%2Fpatron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toland%2Fpatron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toland%2Fpatron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toland","download_url":"https://codeload.github.com/toland/patron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245414347,"owners_count":20611357,"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-07-31T13:00:53.724Z","updated_at":"2025-03-25T06:31:59.313Z","avatar_url":"https://github.com/toland.png","language":"C","readme":"# Patron\n\n[![Build Status](https://travis-ci.org/toland/patron.svg?branch=master)](https://travis-ci.org/toland/patron)\n\nPatron is a Ruby HTTP client library based on libcurl. It does not try to expose\nthe full \"power\" (read complexity) of libcurl but instead tries to provide a\nsane API while taking advantage of libcurl under the hood.\n\n## Usage\n\nFirst, you instantiate a Session object. You can set a few\ndefault options on the Session instance that will be used by all subsequent\nrequests:\n\n```ruby\nsess = Patron::Session.new\nsess.timeout = 10\nsess.base_url = \"http://myserver.com:9900\"\nsess.headers['User-Agent'] = 'myapp/1.0'\n```\n\nYou can set options with a hash in the constructor:\n\n```ruby\nsess = Patron::Session.new({ :timeout =\u003e 10,\n                             :base_url =\u003e 'http://myserver.com:9900',\n                             :headers =\u003e {'User-Agent' =\u003e 'myapp/1.0'} } )\n```\n\nOr the set options in a block:\n\n```ruby\nsess = Patron::Session.new do |patron|\n    patron.timeout = 10\n    patron.base_url = 'http://myserver.com:9900'\n    patron.headers = {'User-Agent' =\u003e 'myapp/1.0'}\nend\n```\n\nOutput debug log:\n\n```ruby\nsess.enable_debug \"/tmp/patron.debug\"\n```\n\nThe Session is used to make HTTP requests.\n\n```ruby\nresp = sess.get(\"/foo/bar\")\n```\n\nRequests return a Response object:\n\n```ruby\nif resp.status \u003c 400\n  puts resp.body\nend\n```\n\nThe GET, HEAD, PUT, POST and DELETE operations are all supported.\n\n```ruby\nsess.put(\"/foo/baz\", \"some data\")\nsess.delete(\"/foo/baz\")\n```\n\nYou can ship custom headers with a single request:\n\n```ruby\nsess.post(\"/foo/stuff\", \"some data\", {\"Content-Type\" =\u003e \"text/plain\"})\n```\n\n## Threading\n\nBy itself, the `Patron::Session` objects are not thread safe (each `Session` holds a single `curl_state` pointer\nfrom initialization to garbage collection). At this time, Patron has no support for `curl_multi_*` family of functions \nfor doing concurrent requests. However, the actual code that interacts with libCURL does unlock the RVM GIL,\nso using multiple `Session` objects in different threads actually enables a high degree of parallelism.\nFor sharing a resource of sessions between threads we recommend using the excellent [connection_pool](https://rubygems.org/gems/connection_pool) gem by Mike Perham.\n\n```ruby\npatron_pool = ConnectionPool.new(size: 5, timeout: 5) { Patron::Session.new }\npatron_pool.with do |session|\n  session.get(...)\nend\n```\n\nSharing Session objects between requests will also allow you to benefit from persistent connections (connection reuse), see below.\n\n## Persistent connections\n\nPatron follows the libCURL guidelines on [connection reuse.](https://everything.curl.dev/libcurl/connectionreuse.html) If you create the Session\nobject once and use it for multiple requests, the same libCURL handle is going to be used across these requests and if requests go to\nthe same hostname/port/protocol the connection should get reused.\n\n## Performance with parallel requests\n\nWhen performing the libCURL request, Patron goes out of it's way to unlock the GVL (global VM lock) to allow other threads to be scheduled\nin parallel. The GVL is going to be released when the libCURL request starts, and will then be shortly re-acquired to provide the progress\ncallback - if the callback has been configured, and then released again until the libCURL request has been performed and the response has\nbeen read in full. This allows one to execute multiple libCURL requests in parallel, as well as perform other activities on other MRI threads\nthat are currently active in the process.\n\n## Requirements\n\nPatron 1.0 and up requires MRI Ruby 2.3 or newer. The 0.x versions support\nRuby 1.9.3 and these versions get tagged and developed on the `v0.x` branch.\n\nA recent version of libCURL is required. We recommend at least 7.19.4 because\nit [supports limiting the protocols](https://curl.haxx.se/libcurl/c/CURLOPT_PROTOCOLS.html),\nand that is very important for security - especially if you follow redirects. \n\nOn OSX the provided libcurl is sufficient if you are not using fork+SSL combination (see below).\nYou will have to install the libcurl development packages on Debian or Ubuntu. Other Linux systems are probably\nsimilar. For Windows we do not have an established build instruction at the moment, unfortunately.\n\n## Forking webservers on macOS and SSL\n\nCurrently, [an issue is at play](https://github.com/curl/curl/issues/788) with OSX builds of `curl` which use\nApple's SecureTransport. Such builds (which Patron is linking to), are causing segfaults when performing HTTPS\nrequests in forked subprocesses. If you need to check whether your system is affected,\nrun the Patron test suite by performing\n\n    $ bundle install \u0026\u0026 bundle exec rspec\n\nin the Patron install directory. Most default curl configurations on OSX (both\nthe Apple-shipped version and the version available via Homebrew) are linked to\nSecureTransport and are likely to be affected. This issue may also manifest in\nforking webserver implementations (such as Unicorn or Passenger) and in forking\njob execution engines (such as resque), so even though you may not be using\n`fork()` directly your server engine might be doing it for you.\n\nTo circumvent the issue, you need to build `curl` with OpenSSL via homebrew.\nWhen doing so, `curl` will use openssl as it's SSL driver. You also need to\nchange the Patron compile flag:\n\n\n    $ brew install curl-openssl \u0026\u0026 \\\n        gem install patron -- --with-curl-config=/usr/local/opt/curl-openssl/bin/curl-config\n\nYou can also save this parameter for all future Bundler-driven gem installs by\nsetting this flag in Bundler proper:\n\n    $ bundle config build.patron --with-curl-config=/usr/local/opt/curl-openssl/bin/curl-config\n\n## Installation\n\n    sudo gem install patron\n\nCopyright (c) 2008 The Hive\n","funding_links":[],"categories":["Web Apps, Services \u0026 Interaction","C","HTTP","HTTP Clients and tools"],"sub_categories":["HTTP clients"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoland%2Fpatron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoland%2Fpatron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoland%2Fpatron/lists"}