<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Over-k</title>
    <description>The latest articles on DEV Community by Over-k (@overk).</description>
    <link>https://dev.to/overk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1214305%2F1372fb7a-e071-4f61-b8f3-ee4cb7b30fda.jpeg</url>
      <title>DEV Community: Over-k</title>
      <link>https://dev.to/overk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/overk"/>
    <language>en</language>
    <item>
      <title>Route Components: Query, Params, and Body</title>
      <dc:creator>Over-k</dc:creator>
      <pubDate>Sun, 31 Dec 2023 23:47:58 +0000</pubDate>
      <link>https://dev.to/overk/route-components-query-params-and-body-9jl</link>
      <guid>https://dev.to/overk/route-components-query-params-and-body-9jl</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
The distinctions between query parameters, route parameters (params), and request body is crucial. Let's dive into each and unravel their unique roles in building robust APIs and some practical guidelines for each type to reinforce best practices:&lt;br&gt;
(In the realm of Express.js)&lt;/p&gt;
&lt;h1&gt;
  
  
  1. Query Parameters:
&lt;/h1&gt;

&lt;p&gt;Query parameters are key-value pairs appended to the URL, typically used for filtering or specifying actions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /api/posts?tag=JavaScript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const tag = req.query.tag;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Avoid Sensitive Information
&lt;/h3&gt;

&lt;p&gt;Do not include sensitive information like passwords in query parameters.&lt;br&gt;
Query parameters are often visible in URLs and can be logged, exposing sensitive data. Instead, use them for non-sensitive information like filters or flags.&lt;/p&gt;
&lt;h1&gt;
  
  
  2. Route Parameters (Params):
&lt;/h1&gt;

&lt;p&gt;Params are variables in the route path, extracting values dynamically. Useful for identifying a specific resource.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /api/users/:id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userId = req.params.id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Validate and Sanitize Inputs
&lt;/h3&gt;

&lt;p&gt;Always validate and sanitize route parameters to prevent malicious input.&lt;br&gt;
Route parameters come directly from the URL, making them susceptible to attacks. Ensure they meet expected criteria and sanitize them to prevent issues like SQL injection.&lt;/p&gt;
&lt;h1&gt;
  
  
  3.Request Body:
&lt;/h1&gt;

&lt;p&gt;The request body carries data, often in JSON format, for operations like creating or updating resources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST /api/users with body { "name": "OverK", "age": 0 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { name, age } = req.body;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Use HTTPS for Sensitive Data
&lt;/h3&gt;

&lt;p&gt;When sending sensitive information in the request body, ensure your API uses HTTPS for secure data transmission.&lt;/p&gt;

&lt;p&gt;The request body is suitable for carrying sensitive data, but transmitting it over an unsecured connection could expose the information. HTTPS encrypts the data during transmission.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Understanding when and how to use query parameters, route parameters, and request body is fundamental for effective Express.js API development. Each serves a distinct purpose, contributing to the flexibility and functionality of your endpoints.&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
