<?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: moalmit</title>
    <description>The latest articles on DEV Community by moalmit (@moalmit).</description>
    <link>https://dev.to/moalmit</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1080786%2F4931c2d7-99da-4b39-80e7-7f5bae586bca.png</url>
      <title>DEV Community: moalmit</title>
      <link>https://dev.to/moalmit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/moalmit"/>
    <language>en</language>
    <item>
      <title>RESTful vs. Custom Routes</title>
      <dc:creator>moalmit</dc:creator>
      <pubDate>Sat, 07 Oct 2023 10:25:33 +0000</pubDate>
      <link>https://dev.to/moalmit/restful-vs-custom-routes-1bin</link>
      <guid>https://dev.to/moalmit/restful-vs-custom-routes-1bin</guid>
      <description>&lt;p&gt;In web development, rotes are used to define how different URLs (Uniform Resource Locators) map to specific actions or resources withing a web application. There are two common approaches to defining routes: RESTful routes and custom routes.&lt;/p&gt;

&lt;p&gt;What are routes?&lt;br&gt;
In the context of URLs, routes typically refer to a way of specifying a particular resource or action within a web application or website. Routes are used to define the structure of URLs and determine &lt;strong&gt;how a web server or we application should respond to incoming requests.&lt;/strong&gt; &lt;br&gt;
Routes are a fundamental part of web development and are often used in combination with web frameworks and content management systems (CMS) to build dynamic and organized websites.&lt;/p&gt;

&lt;p&gt;How routes work in URLs?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Base URL&lt;/strong&gt;: Every website or web application has a base URL, which is the &lt;strong&gt;starting point&lt;/strong&gt; for all its routes. &lt;br&gt;
For example, in the URL &lt;a href="https://www.example.com/"&gt;https://www.example.com/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://example.com/"&gt;https://example.com/&lt;/a&gt; is the &lt;strong&gt;base URL&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Route Path&lt;/strong&gt;: The route path is the part of the URL that comes &lt;strong&gt;after&lt;/strong&gt; the base URL and specifies a particular resource or action. It is often used to represent different pages or functionality within a website. &lt;br&gt;
For example, in the URL  &lt;a href="https://www.example.com/products"&gt;https://www.example.com/products&lt;/a&gt;&lt;br&gt;
/products/ is the &lt;strong&gt;route path&lt;/strong&gt; indicating that the user is accessing the products page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Route Parameters&lt;/strong&gt;: Routes can also include parameters, which are dynamic values passed in the URL &lt;strong&gt;to provide additional information&lt;/strong&gt;. &lt;br&gt;
For example, in the URL &lt;a href="https://example.com/products/123"&gt;https://example.com/products/123&lt;/a&gt;&lt;br&gt;
123 could be a route parameter representing a specific product ID. Web applications can use these parameters to fetch data or perform actions to that parameter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Route Handling&lt;/strong&gt;: On the &lt;strong&gt;server side&lt;/strong&gt;, wed frameworks and applications are configured to handle specific route paths. When a user makes a request to a URL, &lt;strong&gt;the server uses the route path&lt;/strong&gt; to determine which code or controller should be executed to generate the appropriate response. This is often referred to as &lt;strong&gt;routing or route handling&lt;/strong&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTTP Methods&lt;/strong&gt;: Routes can also be associated with specific HTTP methods (e.g., GET, POST, PUT, DELETE) to determine what action should be taken when a request is made. For example, a GET request to /products/ might &lt;strong&gt;retrieve&lt;/strong&gt; a list of products, while a POST request &lt;strong&gt;to the same path&lt;/strong&gt; might &lt;strong&gt;add&lt;/strong&gt; a new product to the database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Route Variables&lt;/strong&gt;: Some web frameworks allow for route variables or placeholders within route paths. These placeholders can match various values and provide flexibility in routing. &lt;br&gt;
For example /products/{category} could match URLs like /products/electronics and /products/clothing with 'electronics' and 'clothing' being route variables that can be used in the server-side code.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Routes in URLs help organize and structure web applications by specifying how URLs should map to specific actions or resources. They are a key component of modern web development, enabling the creation of dynamic and interactive websites. Different web frameworks and CMSs have their own ways of defining and handling routes, but the basic concept remains consistent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RESTful Routes&lt;/strong&gt;&lt;br&gt;
REST (Representational State Transfer) is an architectural style that encourages a standardized way of designing web services and APIs. &lt;br&gt;
RESTful routes are based on the principles of REST and adhere to a set of conventions for mapping HTTP methods (GET, POST, POST, PUT, DELETE) to CRUD (Create, Read, Update, Delete) operations on resources.&lt;br&gt;
RESTful routes typically follow a structured pattern, such as:&lt;/p&gt;

&lt;p&gt;GET /resource (retrieve a list of resources)&lt;br&gt;
GET /resource/:id (retrieve a specific resource by its unique identifier)&lt;br&gt;
POST /resource (Create a new resource)&lt;br&gt;
PUT /resource/:id (update a specific resource)&lt;br&gt;
DELETE /resource/:id (Delete a specific resource)&lt;/p&gt;

&lt;p&gt;RESTful routes provide a clear and predictable way of interacting with resources, making it easier for developers to understand and work with APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Custom Routes&lt;/strong&gt;&lt;br&gt;
As the name suggests, allow developers to define routes that don't necessarily adhere to RESTful conventions. They provide more flexibility in how URLs map to actions or resources within an application.&lt;/p&gt;

&lt;p&gt;Custom routes can be used when we have specific requirements that don't fit neatly into the standard RESTful CRUD operations. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Implementing complex search functionality&lt;/li&gt;
&lt;li&gt;Creating actions that don't directly map to CRUD operations&lt;/li&gt;
&lt;li&gt;Handling legacy APIs or integrating with external services that have their own URL structures&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Custom routes are often used when we need to design an API or web application that doesn't align perfectly with the RESTful model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to choose RESTful Routes vs. Custom Routes?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RESTful Routes&lt;/strong&gt;: Use RESTful routes when we want to adhere to REST principles and have a straightforward way of defining CRUD operations on resources. This approach is suitable for most applications, especially when we want a clear and standardized API design.&lt;br&gt;
&lt;strong&gt;Custom Routes&lt;/strong&gt;: Choose custom routes when our application's requirements are more complex or when we need to deviate from RESTful conventions. Custom routes provide the flexibility to define routes that meet our specific needs.&lt;/p&gt;

&lt;p&gt;It's important to note that these approaches are not mutually exclusive, and we can often mix RESTful and custom routes within the same application, using each where it makes the most sense. The choice between RESTful and custom routes depends on the specific goals and requirements of our project.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>SQL database vs. Excel</title>
      <dc:creator>moalmit</dc:creator>
      <pubDate>Sun, 27 Aug 2023 12:33:16 +0000</pubDate>
      <link>https://dev.to/moalmit/sql-database-vs-excel-3dio</link>
      <guid>https://dev.to/moalmit/sql-database-vs-excel-3dio</guid>
      <description>&lt;p&gt;With very large and complex datasets, Excel solution is not very convenient for an organization with that size of datasets. Excel files support a maximum size of: 1,048,576 rows by 16,384 columns: &lt;a href="https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3"&gt;https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and in practice the limit is such smaller than that because many personal computers can't handle that amount of data along with Excel's user interface at the same time.&lt;/p&gt;

&lt;p&gt;Furthermore, while having a single very large table may not be so bad, the situation becomes more complicated when we have to look up the data in that table in another very large table, which in turn references another table, etc. After a bunch of &lt;code&gt;VLOOKUP&lt;/code&gt; s across several large tables, not only our Excel will crash, but we will also risk losing our data.&lt;/p&gt;

&lt;p&gt;On top of that, collaboration is difficult in Excel, how would we allow our colleagues to work together on the same spreadsheet? One option could be to use Excel Online or Google Spreadsheets, but although these tools are excellent for collaboration on small datasets, they are not optimized for tasks like the one we are describing.&lt;/p&gt;

&lt;p&gt;Add the need to input data from online forms and use it in online dashboards that can be accessed by many people at once, we need a database engine instead. This is a piece of software which is purpose-built to do all the things just mentioned in a very efficient and secure way.&lt;/p&gt;

&lt;p&gt;The database is the classic location where modern organizations have chosen to store their data for professional use. An informal way to understand database is as "spreadsheets of spreadsheets", that is, spreadsheets that link other (potentially many) spreadsheets. Their advantage over Excel is that databases have very strict rules on what is allowed and what not, thus preventing chaos and data loss, and have extremely good performance. Some popular database engines are:&lt;/p&gt;

&lt;p&gt;1) Microsoft SQL Server&lt;br&gt;
2) Oracle Database&lt;br&gt;
3) MySQL (open-source)&lt;br&gt;
4) PostgreSQL (open-source)&lt;br&gt;
5) SQLite (open-source)&lt;/p&gt;

&lt;p&gt;We might have noticed that the letters "SQL" appear in several of the names of these products. That is because just as in Excel we have formulas, we can have formulas in databases, and the language we use to write them is called SQL (Structured Query Language). SQL syntax and functions are standardized across database engines for the most part.&lt;/p&gt;

&lt;p&gt;SQLite stores tables by compressing them into a single file of extension &lt;code&gt;.db&lt;/code&gt; . Primary and foreign keys are very important concepts.&lt;/p&gt;

&lt;p&gt;Primary keys:&lt;br&gt;
1) Uniquely identify a record in the table. Their name usually includes the word "ID". For example, &lt;code&gt;CustomerID&lt;/code&gt; is the primary key of the Customer table, &lt;code&gt;AgentID&lt;/code&gt; is the primary key of the Agent table, and &lt;code&gt;CallID&lt;/code&gt; is the primary key of the call table&lt;br&gt;
2) Do not accept null values (they shouldn't, because the are being used to identify the record)&lt;br&gt;
3) Are limited to one per table.&lt;/p&gt;

&lt;p&gt;On the other hand, foreign keys:&lt;br&gt;
1) Are a field in the table that is the primary key in another table&lt;br&gt;
2) Can accept null values&lt;br&gt;
3) Are not limited in any way per table. For example, the a Call table has 2 foreign keys: &lt;code&gt;AgentID&lt;/code&gt; and &lt;code&gt;CustomerID&lt;/code&gt; pointing to the Agent and Customer tables, respectively.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The (key) prop in React</title>
      <dc:creator>moalmit</dc:creator>
      <pubDate>Sun, 02 Jul 2023 02:05:17 +0000</pubDate>
      <link>https://dev.to/moalmit/the-key-prop-in-react-105c</link>
      <guid>https://dev.to/moalmit/the-key-prop-in-react-105c</guid>
      <description>&lt;p&gt;Working with arrays in React may lead to React internal warning message that can be viewed in the browser console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Warning: Each child in a list should have a unique "key" prop.
Check the render method of `Array name`.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using a special key prop allows React internally to keep track of each element in the array of JSX, so that in case any of the elements are added, updated or deleted, React can optimize performance and keep track internally of those changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Numbers(){
   const numbers = [1, 2, 3, 4, 5]

   const newNumbers = numbers.map(number=&amp;gt; { 
     return &amp;lt;li&amp;gt;{number}&amp;lt;/li&amp;gt;
    }
return (
   &amp;lt;div&amp;gt;
      &amp;lt;li&amp;gt;
         {newNumbers}
      &amp;lt;/li&amp;gt;
   &amp;lt;/div
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in the example above, the error message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Warning: Each child in a list should have a unique "key" prop.
  Check the render method of `newNumbers`.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will be shown on the browser console and to fix this error we must give each (li) element a special key prop, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   const newNumbers = numbers.map(number=&amp;gt; { 
     return (
      &amp;lt;li&amp;gt; key={number}
        {number}
      &amp;lt;/li&amp;gt;
      )
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This special key prop allows React internally to keep track of each element in the array of JSX, so that in case any of the elements are added, updated, or deleted, React can optimize performance and keep track internally of those changes. &lt;/p&gt;

&lt;p&gt;The key should be a unique value associated with each element from the array. Since each element in the array is unique, we can just use each element for the key prop.&lt;/p&gt;

&lt;p&gt;Any time we are creating an array of JSX elements, we must use the key prop.&lt;/p&gt;

&lt;p&gt;Let's see a couple more examples of how this key prop can be used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With Objects&lt;/strong&gt;&lt;br&gt;
It is often best to use the objects's id as the key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const users = [
  { id: 1, firstName: "Duane", lastname: "Watson" },
  { id: 2, firstName: "Duane", lastname: "Johnson" },
]

const userHeadings = users.map(user =&amp;gt; {
   return &amp;lt;h1 key={user.id}&amp;gt;{user.firstaName}&amp;lt;/h1&amp;gt;
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;With Non-Unique Arrays&lt;/strong&gt;&lt;br&gt;
If the array elements are not unique, and can't use the id, the element index position might be used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [0, 1, 2, 3, 4, 5]

const newNumbers = numbers.map((number, index)=&amp;gt; {
  return &amp;lt;div key={index}&amp;lt;/div&amp;gt;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this will make the error message go away, it's not necessarily the best approach and React recommend only using the index as a last resort.&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>Using .map() Method To Copy An Array</title>
      <dc:creator>moalmit</dc:creator>
      <pubDate>Sun, 14 May 2023 15:01:52 +0000</pubDate>
      <link>https://dev.to/moalmit/using-map-method-to-copy-an-array-5h9p</link>
      <guid>https://dev.to/moalmit/using-map-method-to-copy-an-array-5h9p</guid>
      <description>&lt;p&gt;I started this journey on 2023-02-27 with a basic knowledge of computer programming.&lt;br&gt;
  When I see a web page and look at the "source code", I am wondering how the web page works. Now, after 11 weeks of study, I found that the JavaScript coding is the "source" that does most things to the web page behind the scenes.&lt;/p&gt;

&lt;p&gt;Moving forward with JavaScript, I learned essential skills on creating documents with HTML, styling/positioning the documents' content with CSS, and using JavaScript to respond to events. &lt;/p&gt;

&lt;p&gt;Breaking down the JavaScript part of web programming into three "pillars" that constitute the heart of web programming:&lt;/p&gt;

&lt;p&gt;1) Recognizing events.&lt;br&gt;
2) Manipulate DOM.&lt;br&gt;
3) Communicate with server. &lt;/p&gt;

&lt;p&gt;One interesting thing I learned about copying an array nondestructively (leaving the original array intact) is using the map method to copy an array, as in this example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8gD7uMsS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8dspdrbx8aw9uvfypr25.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8gD7uMsS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8dspdrbx8aw9uvfypr25.png" alt="Image description" width="261" height="91"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The way that JavaScript works to manipulate HTML and CSS in real-time allows for the creation of dynamic and interactive web pages, enhances the user experience, and makes web pages more engaging.&lt;br&gt;
  In conclusion, JavaScript is a versatile and powerful language that is essential for building modern web applications. Its ease of use, support for OOP and functional programming, and vast ecosystem of libraries and frameworks make it a popular choice for developers worldwide. Whether you are a beginner or an experienced developer, learning JavaScript is a must if you want to build dynamic and interactive web applications.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
