<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[cURL: Talk to Server from Your Terminal]]></title><description><![CDATA[cURL: Talk to Server from Your Terminal]]></description><link>https://curlforbeginnersbyamrit.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 15:31:05 GMT</lastBuildDate><atom:link href="https://curlforbeginnersbyamrit.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[cURL for Beginners: Talk to Any Server from Your Terminal]]></title><description><![CDATA[cURL: A Command-Line Tool and Library for Transferring Data with URLs
cURL is a tool that allows you to send a request to a server from your terminal and view the response.
While browsers communicate with servers using a graphical interface, cURL let...]]></description><link>https://curlforbeginnersbyamrit.hashnode.dev/curl-for-beginners-talk-to-any-server-from-your-terminal</link><guid isPermaLink="true">https://curlforbeginnersbyamrit.hashnode.dev/curl-for-beginners-talk-to-any-server-from-your-terminal</guid><category><![CDATA[curl]]></category><category><![CDATA[api]]></category><category><![CDATA[Apitesting]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[amrit rajput]]></dc:creator><pubDate>Fri, 23 Jan 2026 15:56:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1769177905778/6a1ba9da-0870-4ecd-a943-a70fe2ecdadc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-curl-a-command-line-tool-and-library-for-transferring-data-with-urls">cURL: <strong>A Command-Line Tool and Library</strong> for Transferring Data with URLs</h3>
<p>cURL is a tool that allows you to send a request to a server from your terminal and view the response.</p>
<p>While browsers communicate with servers using a graphical interface, cURL lets you interact with servers through the terminal in text format.</p>
<p>This tool also supports the use of all the following protocols: DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, and TFTP.</p>
<p>Example:</p>
<pre><code class="lang-powershell"><span class="hljs-built_in">curl</span> https://example.com
</code></pre>
<p>This sends a request to the server and prints the response (HTML/JSON/text).</p>
<h3 id="heading-why-programmers-use-it">Why programmers use it:</h3>
<ol>
<li><strong>Test APIs quickly</strong></li>
</ol>
<ul>
<li><p>Check if an API endpoint is working</p>
</li>
<li><p>Get data in JSON format instantly</p>
</li>
</ul>
<ol start="2">
<li><strong>Debug backend issues</strong></li>
</ol>
<ul>
<li><p>See status codes like <code>200</code>, <code>404</code>, <code>500</code></p>
</li>
<li><p>Understand why a request is failing</p>
</li>
</ul>
<ol start="3">
<li><strong>Send requests without a frontend</strong></li>
</ol>
<ul>
<li>Backend can be tested even if the frontend is not built yet</li>
</ul>
<ol start="4">
<li><strong>Check server response clearly</strong></li>
</ol>
<ul>
<li><p>You can view response headers + body</p>
</li>
<li><p>Helps in troubleshooting authentication, CORS, etc.</p>
</li>
</ul>
<ol start="5">
<li><strong>Automate API calls</strong></li>
</ol>
<ul>
<li>Useful in scripts, CI/CD, testing, and deployments</li>
</ul>
<h3 id="heading-first-curl-command-testing-a-website-in-seconds"><mark>First cURL Command: Testing a Website in Seconds:</mark></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1769179506251/911e10a5-63c3-4dac-b816-6866178da9e6.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-meaning-of-output">Meaning of output:</h3>
<p><code>301 Moved</code><br />That means Google is <strong>redirecting</strong> you from:</p>
<p><a target="_blank" href="https://google.com"><code>https://google.com</code></a> → <a target="_blank" href="https://www.google.com/"><code>https://www.google.com/</code></a></p>
<h3 id="heading-example">Example</h3>
<pre><code class="lang-powershell">curl.exe <span class="hljs-literal">-L</span> https://google.com
</code></pre>
<p><strong>Output (trimmed):</strong></p>
<pre><code class="lang-powershell">&lt;!doctype html&gt;
&lt;html lang=<span class="hljs-string">"en-IN"</span>&gt;
&lt;head&gt;
  &lt;meta charset=<span class="hljs-string">"UTF-8"</span>&gt;
  &lt;title&gt;Google&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  ...
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>Note: Output is trimmed for readability.</p>
<hr />
<h2 id="heading-1-get-fetch-data">1. GET (Fetch data)</h2>
<h3 id="heading-get-all-posts">Get all posts</h3>
<pre><code class="lang-powershell">curl.exe https://jsonplaceholder.typicode.com/posts
</code></pre>
<h3 id="heading-get-a-single-post">Get a single post</h3>
<pre><code class="lang-powershell">curl.exe https://jsonplaceholder.typicode.com/posts/<span class="hljs-number">1</span>
</code></pre>
<hr />
<h2 id="heading-2post-create-new-data">2.POST (Create new data)</h2>
<pre><code class="lang-powershell">curl.exe <span class="hljs-literal">-X</span> POST https://jsonplaceholder.typicode.com/posts ^
  <span class="hljs-literal">-H</span> <span class="hljs-string">"Content-Type: application/json"</span> ^
  <span class="hljs-literal">-d</span> <span class="hljs-string">"{\"</span>title\<span class="hljs-string">":\"</span>hello\<span class="hljs-string">",\"</span>body\<span class="hljs-string">":\"</span>first post\<span class="hljs-string">",\"</span>userId\<span class="hljs-string">":1}"</span>
</code></pre>
<p><code>-d</code> = data you are sending<br /><code>Content-Type</code> tells server it’s JSON</p>
<hr />
<h2 id="heading-3put-replace-full-data">3.PUT (Replace full data)</h2>
<p>PUT usually means <strong>replace the entire object</strong>.</p>
<pre><code class="lang-powershell">curl.exe <span class="hljs-literal">-X</span> PUT https://jsonplaceholder.typicode.com/posts/<span class="hljs-number">1</span> ^
  <span class="hljs-literal">-H</span> <span class="hljs-string">"Content-Type: application/json"</span> ^
  <span class="hljs-literal">-d</span> <span class="hljs-string">"{\"</span>id\<span class="hljs-string">":1,\"</span>title\<span class="hljs-string">":\"</span>updated title\<span class="hljs-string">",\"</span>body\<span class="hljs-string">":\"</span>updated body\<span class="hljs-string">",\"</span>userId\<span class="hljs-string">":1}"</span>
</code></pre>
<hr />
<h2 id="heading-4-patch-update-only-some-fields">4. PATCH (Update only some fields)</h2>
<p>PATCH means <strong>partial update</strong>.</p>
<pre><code class="lang-powershell">curl.exe <span class="hljs-literal">-X</span> PATCH https://jsonplaceholder.typicode.com/posts/<span class="hljs-number">1</span> ^
  <span class="hljs-literal">-H</span> <span class="hljs-string">"Content-Type: application/json"</span> ^
  <span class="hljs-literal">-d</span> <span class="hljs-string">"{\"</span>title\<span class="hljs-string">":\"</span>only title updated\<span class="hljs-string">"}"</span>
</code></pre>
<h2 id="heading-5send-headers-authorization-token-etc">5.Send Headers (Authorization / Token / etc.)</h2>
<p>Example with a custom header:</p>
<pre><code class="lang-powershell">curl.exe https://jsonplaceholder.typicode.com/posts/<span class="hljs-number">1</span> ^
  <span class="hljs-literal">-H</span> <span class="hljs-string">"Accept: application/json"</span> ^
  <span class="hljs-literal">-H</span> <span class="hljs-string">"X-My-App: test"</span>
</code></pre>
<h3 id="heading-authorization-header-example-very-common-in-real-apis">Authorization header example (very common in real APIs)</h3>
<pre><code class="lang-powershell">curl.exe https://api.example.com/profile ^
  <span class="hljs-literal">-H</span> <span class="hljs-string">"Authorization: Bearer YOUR_TOKEN"</span>
</code></pre>
<h2 id="heading-6-see-response-headers-status-code">6. See Response Headers + Status Code</h2>
<h3 id="heading-show-headers-body">Show headers + body</h3>
<pre><code class="lang-powershell">curl.exe <span class="hljs-literal">-i</span> https://jsonplaceholder.typicode.com/posts/<span class="hljs-number">1</span>
</code></pre>
<h3 id="heading-only-headers-no-body">Only headers (no body)</h3>
<pre><code class="lang-powershell">curl.exe <span class="hljs-literal">-I</span> https://jsonplaceholder.typicode.com/posts/<span class="hljs-number">1</span>
</code></pre>
<hr />
<h2 id="heading-7-save-response-to-a-file">7. Save Response to a File</h2>
<h3 id="heading-save-json-output-to-a-file">Save JSON output to a file</h3>
<pre><code class="lang-powershell">curl.exe https://jsonplaceholder.typicode.com/posts <span class="hljs-literal">-o</span> posts.json
</code></pre>
<h2 id="heading-common-mistakes-beginners-make-with-curl">Common Mistakes Beginners Make with cURL</h2>
<ul>
<li><p>Using <code>curl</code> in PowerShell instead of <code>curl.exe</code></p>
</li>
<li><p>Forgetting <code>https://</code> in the URL</p>
</li>
<li><p>Not following redirects (301/302) → missing <code>-L</code></p>
</li>
<li><p>Confusing <strong>GET</strong> and <strong>POST</strong></p>
</li>
<li><p>Sending JSON without <code>Content-Type: application/json</code></p>
</li>
<li><p>Writing wrong JSON format / escaping issues</p>
</li>
<li><p>Expecting a browser-like UI output (cURL shows raw data)</p>
</li>
<li><p>Not checking status codes and headers (missing <code>-i</code>)</p>
</li>
<li><p>Hitting the wrong endpoint / missing slash <code>/</code></p>
</li>
<li><p>Copy-pasting Linux/mac commands directly into Windows (line breaks issue)</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion:</h2>
<p><strong>cURL</strong> is a command-line tool used to <strong>send requests to servers and APIs</strong> directly from the terminal. It helps programmers <strong>test and debug backend endpoints quickly</strong> by checking the <strong>response data</strong>, <strong>status codes</strong> (like 200, 404), and <strong>headers</strong>. With cURL, you can perform basic HTTP operations like <strong>GET (fetch data)</strong> and <strong>POST (send data)</strong> without needing a browser or frontend, making it a fast and powerful tool for API testing and backend development.</p>
]]></content:encoded></item></channel></rss>