{"id":1618,"date":"2024-02-16T00:00:00","date_gmt":"2024-02-16T05:00:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=1618"},"modified":"2024-02-21T08:01:12","modified_gmt":"2024-02-21T13:01:12","slug":"curl-cheat-sheet","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/curl-cheat-sheet\/","title":{"rendered":"curl Cheat Sheet"},"content":{"rendered":"\n<p>Curl (Client for URLs) is a versatile command-line tool for making HTTP requests. It supports various protocols and is widely used for testing APIs, downloading files, and more.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Basic Usage:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>curl [URL]<\/code><\/td><td>Make a GET request.<\/td><\/tr><tr><td><code>curl -o [output_file] [URL]<\/code><\/td><td>Save output to a file.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>HTTP Methods:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>curl -X POST -d \"data\" [URL]<\/code><\/td><td>Make a POST request with data.<\/td><\/tr><tr><td><code>curl -X PUT -d \"data\" [URL]<\/code><\/td><td>Make a PUT request with data.<\/td><\/tr><tr><td><code>curl -X DELETE [URL]<\/code><\/td><td>Make a DELETE request.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Headers:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>curl -H \"Header: Value\" [URL]<\/code><\/td><td>Include headers in the request.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Follow Redirects:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>curl -L [URL]<\/code><\/td><td>Follow redirects.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Authentication:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>curl -u username:password [URL]<\/code><\/td><td>Basic authentication.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Upload Files:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>curl -X POST -F \"file=@\/path\" [URL]<\/code><\/td><td>Upload a file with POST.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Download Resume:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>curl -C - -O [URL]<\/code><\/td><td>Resume download.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Show Request and Response Details:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>curl -v [URL]<\/code><\/td><td>Verbose mode, show details.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output to Dev Null:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>curl -s -o \/dev\/null [URL]<\/code><\/td><td>Suppress progress and output.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>User Agent:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>curl -A \"UserAgentString\" [URL]<\/code><\/td><td>Set User Agent.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Timeouts:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>curl --connect-timeout 10 [URL]<\/code><\/td><td>Set connection timeout.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Bonus Tips:<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To install <code>curl<\/code> on Debian-based systems:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install curl<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To install <code>curl<\/code> on Red Hat-based systems:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum install curl\r<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>This <code>curl<\/code> cheat sheet provides a concise reference for a variety of HTTP request scenarios. Use these commands to interact with APIs and services effectively, and enhance your command-line capabilities for web interactions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Curl (Client for URLs) is a versatile command-line tool for making HTTP requests. It supports various protocols and is widely used for testing APIs, downloading files, and more. Basic Usage: Command Description curl [URL] Make a GET request. curl -o [output_file] [URL] Save output to a file. HTTP Methods: Command Description curl -X POST -d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1784,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[35],"class_list":["post-1618","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=1618"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1618\/revisions"}],"predecessor-version":[{"id":1619,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1618\/revisions\/1619"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media\/1784"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=1618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=1618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=1618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}