<?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: devlazar</title>
    <description>The latest articles on DEV Community by devlazar (@devlazar).</description>
    <link>https://dev.to/devlazar</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%2F433569%2F3e95f869-d1ba-4ee8-a061-e35f5cf01e5b.jpg</url>
      <title>DEV Community: devlazar</title>
      <link>https://dev.to/devlazar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devlazar"/>
    <language>en</language>
    <item>
      <title>Pros and Cons of Working as a Software Engineer</title>
      <dc:creator>devlazar</dc:creator>
      <pubDate>Fri, 23 Jun 2023 07:38:37 +0000</pubDate>
      <link>https://dev.to/devlazar/pros-and-cons-of-working-as-a-software-engineer-2259</link>
      <guid>https://dev.to/devlazar/pros-and-cons-of-working-as-a-software-engineer-2259</guid>
      <description>&lt;p&gt;Hey, all. 🚀&lt;/p&gt;

&lt;p&gt;So I’ve been working in the IT industry for four and a half years. I worked on a dozen different projects (ten different clients) and thought about sharing the pros and cons of being a Software Engineer by explaining companies and clients/employers that you could be working with/for. This is my experience as well as the experience of my close colleagues, not a generalization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Companies
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Corporate
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Professional Development Opportunities:&lt;/strong&gt; Large corporations often have well-structured training programs, mentorship initiatives, and career development resources in place. These resources can help employees enhance their skills, acquire new knowledge, and advance their careers within the organization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Networking and Collaboration:&lt;/strong&gt; Corporate environments offer opportunities for networking and collaboration with a diverse group of professionals. Working alongside experienced colleagues from different departments and backgrounds can broaden your perspective, foster innovation, and provide valuable connections for future career growth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Competitive Compensation and Benefits:&lt;/strong&gt; Many corporate environments offer competitive salary packages and comprehensive benefits, including health insurance, retirement plans, paid time off, lazy bags, PS5, gym membership, and various employee perks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Established Processes and Resources:&lt;/strong&gt; Large corporations often have well-established processes, tools, and resources in place to support employees in their work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Slow Career Advancement:&lt;/strong&gt; In a corporate setting, career advancement may be slower than in smaller, more agile organizations. Promotion and improvement may be subject to strict criteria, seniority-based systems, or limited availability of higher-level positions. This can lead to frustration for ambitious individuals seeking rapid growth or those who feel their contributions are not adequately recognized or rewarded.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lack of Work-Life Balance:&lt;/strong&gt; Even though you are in a lazy bag playing with PS5 during your break from work, many times you feel that you lack work-life balance. Depending on the project/client, you may experience a lot of pressure to meet deadlines, populate timesheets, do bureaucratic chores, or work overtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Limited Autonomy and Decision-Making Authority:&lt;/strong&gt; Corporate environments often have a top-down decision-making structure, where key decisions are made by higher-level executives. (e.g. I waited almost 2 months for the line Manager to find out about the issue/problem I reported).&lt;/p&gt;

&lt;h3&gt;
  
  
  Outsourcing
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Diverse and Challenging Projects:&lt;/strong&gt; Working in an outsourcing company exposes employees to a wide range of projects across different industries, technologies, and client requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Global Collaboration:&lt;/strong&gt; Outsourcing companies often have a global presence and work with clients from different countries. This enables employees to collaborate with multicultural teams, learn from diverse perspectives, and gain cross-cultural communication skills.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exposure to Best Practices:&lt;/strong&gt; As outsourcing companies serve multiple clients, they tend to follow industry best practices and standards. Working in such an environment exposes employees to efficient project management methodologies, quality assurance processes, and cutting-edge technologies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Career Growth and Advancement:&lt;/strong&gt; Outsourcing companies often have structured career paths, performance evaluation systems, and opportunities for advancement. Employees can progress through different levels of responsibility and seniority based on their skills, experience, and performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Job Insecurity and Uncertainty:&lt;/strong&gt; Outsourcing companies often rely on client contracts for project engagements. This can introduce a level of job insecurity as projects may come to an end, or client priorities may change, affecting the availability of work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variable Workload and Stress:&lt;/strong&gt; Working in an outsourcing company can involve handling multiple projects simultaneously, each with its own timelines and client demands. Balancing competing priorities and managing tight deadlines can lead to high-pressure situations and increased stress levels. (This also depends on the client type)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Limited Earning Opportunities:&lt;/strong&gt; Usually, the outsourcing company takes a substantial cut from the paycheck. It is not unusual — and definitely cruel — for the employees to take as low as 5% of the actual money they made for the company. (Do not generalize this, it depends on various factors, country, country stability, company culture, etc…)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Limited Influence on Project Decisions:&lt;/strong&gt; In an outsourcing company, project decisions are often made by clients or project managers, limiting the influence and autonomy of individual employees. This can result in less control over project direction, decision-making processes, and creative freedom. (This one is questionable and it mainly depends on the client type.)&lt;/p&gt;

&lt;h3&gt;
  
  
  StartUp
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Impact and Influence:&lt;/strong&gt; Startups offer employees the opportunity to have a significant impact and influence on the company’s growth and success. With smaller teams and flatter hierarchies, individuals often have more autonomy, decision-making power, and the ability to shape the direction of the company.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Innovation and Creativity:&lt;/strong&gt; Startups are known for their innovative and creative approaches to problem-solving. They often encourage and foster an entrepreneurial mindset, allowing employees to think outside the box, experiment with new ideas, and contribute to groundbreaking solutions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fast-Paced and Dynamic Environment:&lt;/strong&gt; Startups thrive in a fast-paced and dynamic environment. This can be exhilarating for individuals who enjoy challenges and continuous learning.&lt;br&gt;
Opportunities for Learning and Development: Startups provide excellent opportunities for learning and development. With limited resources, employees are often required to stretch their skill sets and learn new things quickly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Equity and Financial Reward:&lt;/strong&gt; In some cases, startups offer employees the opportunity to receive equity in the company. This can be a significant financial upside if the company experiences growth and success.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Uncertainty and Risk:&lt;/strong&gt; The project might die tomorrow, and money could run out tomorrow for various reasons. In general, startups operate in a highly volatile and uncertain business environment. There is always a risk of failure or closure, especially in the early stages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Long Working Hours:&lt;/strong&gt; Startups often require long working hours and a high level of commitment. The intense workload and fast-paced nature of the work can lead to a poor work-life balance, especially in situations where resources are limited and deadlines are tight.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Limited Resources and Support:&lt;/strong&gt; Startups typically operate with limited resources, including financial, operational, and human resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Role Ambiguity and Multiple Responsibilities:&lt;/strong&gt; Startups often have small teams, which means employees may need to take on multiple roles and responsibilities beyond their primary expertise. This can lead to role ambiguity, stretched capacities, and a lack of specialization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lack of Established Processes and Structure:&lt;/strong&gt; Startups are typically in the early stages of development, which means they may lack well-established processes, systems, and organizational structures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Clients
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Corporate
&lt;/h3&gt;

&lt;p&gt;Obviously — but not as a rule — corporate client (employer) comes with different perks that we mentioned in the Corporate Company section, the best one being development opportunities and networking (knowledge sharing). You have access to senior colleagues with a lot of experience and knowledge, all major and necessary courses, professional training, and similar. There is also — my personal opinion and experience — one major thing that is a huge drawback of working for such a client/employer, and that is that everything is VERY VERY slow. Slow onboarding, slow decisions, slow responses from the people you need, slow promoting. The corporate lather is very high, and it takes time to climb up. Overnight success is virtually impossible.&lt;/p&gt;

&lt;h3&gt;
  
  
  Start-Up
&lt;/h3&gt;

&lt;p&gt;Comes with the perks of creativity, a dynamic environment, faster learning and tech adoption, and the possibility to make some money. Of course, the uncertainty about the future of the project is the biggest drawback. Money can run out tomorrow, and tomorrow you could be out of work — in the worst cases the client could even postpone paying you the previous month(s).&lt;/p&gt;

&lt;h3&gt;
  
  
  Government
&lt;/h3&gt;

&lt;p&gt;It is usually the mix of the two above, with the tendency to lean more toward the Corporate side when it comes to requirements but more to the StartUp side when it comes to certainty, and clarity.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Start-Up that adopted Corporate culture
&lt;/h3&gt;

&lt;p&gt;Probably the one you should avoid the most. There is a delay in communication and decision-making when it comes to clarifying what is needed and what is right to do at a certain point of development. There is pressure to meet VERY VERY tight deadlines. There is urgency when it comes to delivery, and delay when it comes to clarifying features/decisions/intentions. Miscommunications often arise regarding decision-making authority and responsibility. (e.g. Project Manager deciding or having a strong opinion on how long should the developer work on the task) Everything is most of the time urgent and important. Team structure changes a lot. You are following standards (design, architecture, etc…) half the time, and the other half you listen to the requirements and implement them blindly. Initial code and architecture quality are usually not among the top two requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  In General
&lt;/h2&gt;

&lt;p&gt;Pros and Cons of Being a Software Engineer&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lucrative Salaries&lt;/li&gt;
&lt;li&gt;Continuous Learning&lt;/li&gt;
&lt;li&gt;Abundance of Opportunities&lt;/li&gt;
&lt;li&gt;Problem-solving&lt;/li&gt;
&lt;li&gt;Creativity&lt;/li&gt;
&lt;li&gt;Social impact&lt;/li&gt;
&lt;li&gt;Coffee&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Feature Miscommunication&lt;/li&gt;
&lt;li&gt;Client and Stakeholder Management&lt;/li&gt;
&lt;li&gt;Volatile Technology Landscape&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ultimately, the pros and cons of working as a software engineer will vary depending on individual preferences, professional aspirations, personal and professional habits, and the specific work environment. By carefully weighing these factors, individuals can make informed decisions about pursuing a career in software engineering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important skills:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learn how to learn&lt;/li&gt;
&lt;li&gt;Learn how to communicate on different levels&lt;/li&gt;
&lt;li&gt;Offer solutions, do not ask questions&lt;/li&gt;
&lt;li&gt;Evaluate clients/employers as much as they evaluate you&lt;/li&gt;
&lt;li&gt;Know your value&lt;/li&gt;
&lt;li&gt;Know the worth of your time&lt;/li&gt;
&lt;li&gt;Manage time&lt;/li&gt;
&lt;li&gt;Manage people&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>discuss</category>
      <category>career</category>
      <category>programming</category>
    </item>
    <item>
      <title>Tiny Chat App UI</title>
      <dc:creator>devlazar</dc:creator>
      <pubDate>Fri, 03 Mar 2023 13:30:24 +0000</pubDate>
      <link>https://dev.to/devlazar/tiny-chat-app-ui-2gn5</link>
      <guid>https://dev.to/devlazar/tiny-chat-app-ui-2gn5</guid>
      <description>&lt;p&gt;Table Of Contents&lt;br&gt;
        * 🚀INTRO&lt;br&gt;
        * 🏁SOLUTION&lt;br&gt;
        * 🙏THANK YOU&lt;/p&gt;
&lt;h2&gt;
  
  
  🚀 Intro &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hey all, today I give you the tiny chat app UI that you can extend and use to create a good-looking and simple chat application.&lt;/p&gt;

&lt;p&gt;All of the code is in the CodeSandbox don't hesitate to examine and use this code. Ask questions if you have any!&lt;/p&gt;

&lt;p&gt;We'll use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React (TypeScript)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;Tailwindcss&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/@heroicons/react" rel="noopener noreferrer"&gt;heroicons&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://flowbite.com/" rel="noopener noreferrer"&gt;Flowbite&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  🏁 Solution &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/react-typescript-tailwind-chat-ui-fs3x3w"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  🙏 THANK YOU FOR READING!&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hope this helps you in your future work. Cheers! 🍻&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>lambda</category>
      <category>cloudcomputing</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Format large numbers to corresponding abbreviations</title>
      <dc:creator>devlazar</dc:creator>
      <pubDate>Thu, 23 Feb 2023 23:14:33 +0000</pubDate>
      <link>https://dev.to/devlazar/format-large-numbers-to-corresponding-abbreviations-ep7</link>
      <guid>https://dev.to/devlazar/format-large-numbers-to-corresponding-abbreviations-ep7</guid>
      <description>&lt;p&gt;Table Of Contents&lt;br&gt;
        * 🚀INTRO&lt;br&gt;
        * 🏁SOLUTION&lt;br&gt;
        * 🙏THANK YOU&lt;/p&gt;
&lt;h2&gt;
  
  
  🚀 Intro &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hey all! If you ever worked in fintech - or any other number-related field - you probably came across a requirement like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Format a number to the abbreviated version but only if that-and-that criteria are met.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I had such a requirement and the criteria were something like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If a number is less than 1000 show as-is, and no decimal points&lt;/li&gt;
&lt;li&gt;If a number is greater than 1000, abbreviate it to the corresponding string value e.g. 1K, and always use two decimal points e.g. 1233 -&amp;gt; 1.23K.&lt;/li&gt;
&lt;li&gt;If a number is greater than a million do it like 1M, 1.33M&lt;/li&gt;
&lt;li&gt;If a number is a billion do it like 1B, 10.45B, 123.12B&lt;/li&gt;
&lt;li&gt;Same goes for a trillion&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  🏁 Solution &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Here is a simple, short, and sweet solution, and If you tweak it right you can accommodate your own criteria.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://jsfiddle.net/devlazar95/7cahvm81/52//embedded/js,result,html,css//dark" width="100%" height="600"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  🙏 THANK YOU FOR READING!&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hope this helps you in your future work. Cheers! 🍻&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>webscraping</category>
      <category>seo</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Exact match search deeply nested objects - PostgreSQL</title>
      <dc:creator>devlazar</dc:creator>
      <pubDate>Mon, 17 Oct 2022 10:17:53 +0000</pubDate>
      <link>https://dev.to/devlazar/exact-match-search-deeply-nested-objects-postgresql-43li</link>
      <guid>https://dev.to/devlazar/exact-match-search-deeply-nested-objects-postgresql-43li</guid>
      <description>&lt;p&gt;Table Of Contents&lt;br&gt;
        * 🚀INTRO&lt;br&gt;
        * 🎯GOAL&lt;br&gt;
        * 🏁SOLUTION&lt;br&gt;
        * 🙏THANK YOU&lt;/p&gt;
&lt;h2&gt;
  
  
  🚀 Intro &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hi all! In this post I'll try to showcase the problem I faced recently. It is regarding the PostgreSQL database and how to query for an exact text match in the deeply nested objects and array of objects.&lt;/p&gt;
&lt;h2&gt;
  
  
  🎯 Goal &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Let's consider that you are making a platform that allows people to register, create profile, add &lt;strong&gt;skills&lt;/strong&gt; they poses and land a job offer. Let's assume that we are currently interested in creating a search engine that will search only for the exact match of the skill (e.g. "cooking") and It should return only the data that matched the search term.&lt;/p&gt;

&lt;p&gt;Also, let's assume that we are storing the table that has a column called "sections" and it is of "jsonb" type. That object contains objects for "skills" (which contains an array of objects called "items"), "languages", "hobbies" etc.&lt;/p&gt;

&lt;p&gt;Read more about JSON column in &lt;a href="https://www.postgresql.org/docs/14/datatype-json.html" rel="noopener noreferrer"&gt;PostgreSQL docs&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  JSON object example
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;sections:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="err"&gt;skills:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="err"&gt;items:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="w"&gt;
         &lt;/span&gt;&lt;span class="err"&gt;name:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;'cooking'&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="err"&gt;languages:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="err"&gt;hobbies:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So, our current goal is to get the search term the "employer" user entered - in this case 'cooking' and find all the user profiles that match this term exactly.&lt;/p&gt;
&lt;h2&gt;
  
  
  🏁 Solution &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;We can achieve this in the following manner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;user_profile&lt;/span&gt; &lt;span class="n"&gt;up&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;up&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sections&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="s1"&gt;'skills'&lt;/span&gt; &lt;span class="o"&gt;@&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'{"items":[{ "name": "cooking"}]}'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will return all the user profiles from the user_profile table, that matched the skill search term exactly.&lt;/p&gt;

&lt;h2&gt;
  
  
  🙏 THANK YOU FOR READING!&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Please leave a comment, tell me about you, about your work, comment your thoughts, connect with me! &lt;/p&gt;

&lt;p&gt;☕ SUPPORT ME AND KEEP ME FOCUSED!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ko-fi.com/Z8Z33D1HJ" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.ko-fi.com%2Fcdn%2Fkofi4.png%3Fv%3D2" alt="Buy Me a Coffee at ko-fi.com"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have a nice time hacking! 😊&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>sql</category>
      <category>database</category>
      <category>programming</category>
    </item>
    <item>
      <title>Reusable Loader directive - Angular</title>
      <dc:creator>devlazar</dc:creator>
      <pubDate>Sat, 09 Jul 2022 12:39:20 +0000</pubDate>
      <link>https://dev.to/devlazar/reusable-loader-directive-angular-498h</link>
      <guid>https://dev.to/devlazar/reusable-loader-directive-angular-498h</guid>
      <description>&lt;p&gt;Table Of Contents&lt;br&gt;
        * 🚀INTRO&lt;br&gt;
        * 🧪 EXAMPLE USE CASE&lt;br&gt;
        * ⚙ IMPLEMENTATION&lt;br&gt;
        * 🙏THANK YOU&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 INTRO &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hi &lt;strong&gt;all&lt;/strong&gt;! Hope you are all having a great weekend. I am currently working on multiple platforms using &lt;strong&gt;ReactJS&lt;/strong&gt;, &lt;strong&gt;Angular 12&lt;/strong&gt; and &lt;strong&gt;Node.js&lt;/strong&gt;. &lt;/p&gt;




&lt;p&gt;I noticed that Angular is kinda hard to work with in terms of having reusable and easy to use components for &lt;strong&gt;loading&lt;/strong&gt;, &lt;strong&gt;empty&lt;/strong&gt;, &lt;strong&gt;error&lt;/strong&gt; state and similar. So, I wanted to figure out the way of how to create a simple relative ("relative" in terms of where it is placed, which means it is placed in the relative parent element within the HTML)loader component that could just be plugged in into the component and control the loading of the specific component.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧪 EXAMPLE USE CASE &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Let's consider this:&lt;/p&gt;

&lt;p&gt;You are employee of the Stark industries. Tony rings you up:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hey, man. Can you make a simple UI form that will allow me to select the suit type, color and reactor type. The form should be in the dialog?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Of course you would say yes, It is a freakin' Tony Stark xD&lt;/p&gt;

&lt;p&gt;You start listing the requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Dialog component&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Should have 3 inputs, suit type, color and reactor type&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We need to fetch available suits, colors and reactor (let's assume we can fetch it all from one endpoint)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The user should not be able to interact with the component unless everything is loaded&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's see how to implement this!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3lvqNXheb679S/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3lvqNXheb679S/giphy.gif" alt="journey"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚙ [IMPLEMENTATION] &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Our main dialog component (&lt;em&gt;ts file) will have **status&lt;/em&gt;* class member which will tell us if the API call is triggered. It will also have a &lt;strong&gt;form group&lt;/strong&gt; and of course the &lt;strong&gt;data&lt;/strong&gt; that will provide us with the &lt;strong&gt;type of suits&lt;/strong&gt;, &lt;strong&gt;colors&lt;/strong&gt; and &lt;strong&gt;reactor types&lt;/strong&gt;. Of course, we have to create our form and function that will call our API service. It will look something like this.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;IDataResponse&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;suits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;reactors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stark-dialog&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;templateUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./stark-dialogcomponent.html&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;styleUrls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./stark-dialog.component.scss&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StarkDialogComponent&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;OnInit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;loading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;not-loading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;not-loading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;starkForm&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;FormGroup&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;IDataResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;MAT_DIALOG_DATA&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;IDialogData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;_apiService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ApiService&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;_formBuilder&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;FormBuilder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createStarkForm&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;ngOnInit&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;loading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="nx"&gt;fetching&lt;/span&gt; &lt;span class="nx"&gt;logic&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;not-loading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;createStarkForm&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;starkForm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_formBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;selectSuitType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Validators&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;required&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="na"&gt;selectColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Validators&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;required&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="na"&gt;selectReactorType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Validators&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;required&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Our HTML could look something like this&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;mat-dialog-title&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  Choose suit setup
&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;mat-dialog-content&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;[formGroup]=&lt;/span&gt;&lt;span class="s"&gt;"starkForm"&lt;/span&gt; &lt;span class="na"&gt;(submit)=&lt;/span&gt;&lt;span class="s"&gt;"onSubmit()"&lt;/span&gt; &lt;span class="na"&gt;fxLayout=&lt;/span&gt;&lt;span class="s"&gt;"column"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;mat-form-field&lt;/span&gt; &lt;span class="na"&gt;appearance=&lt;/span&gt;&lt;span class="s"&gt;"fill"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;mat-label&amp;gt;&lt;/span&gt;Select suit type&lt;span class="nt"&gt;&amp;lt;/mat-label&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;mat-select&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"selectSuitType"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;mat-option&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let suit of data.suits"&lt;/span&gt; &lt;span class="na"&gt;[value]=&lt;/span&gt;&lt;span class="s"&gt;"suit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
              {{ suit.type }}
            &lt;span class="nt"&gt;&amp;lt;/mat-option&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;/mat-select&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/mat-form-field&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;mat-form-field&lt;/span&gt; &lt;span class="na"&gt;appearance=&lt;/span&gt;&lt;span class="s"&gt;"fill"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;mat-label&amp;gt;&lt;/span&gt;Select color&lt;span class="nt"&gt;&amp;lt;/mat-label&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;mat-select&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"selectColor"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;mat-option&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let color of data.colors"&lt;/span&gt; &lt;span class="na"&gt;[value]=&lt;/span&gt;&lt;span class="s"&gt;"color"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
              {{ color.key }}
            &lt;span class="nt"&gt;&amp;lt;/mat-option&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;/mat-select&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/mat-form-field&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;mat-form-field&lt;/span&gt; &lt;span class="na"&gt;appearance=&lt;/span&gt;&lt;span class="s"&gt;"fill"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;mat-label&amp;gt;&lt;/span&gt;Select reactor type&lt;span class="nt"&gt;&amp;lt;/mat-label&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;mat-select&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"selectReactorType"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;mat-option&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let reactor of data.reactors"&lt;/span&gt; &lt;span class="na"&gt;[value]=&lt;/span&gt;&lt;span class="s"&gt;"reactor"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
              {{ reactor.type }}
            &lt;span class="nt"&gt;&amp;lt;/mat-option&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;/mat-select&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/mat-form-field&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/mat-dialog-content&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;mat-dialog-actions&lt;/span&gt; &lt;span class="na"&gt;align=&lt;/span&gt;&lt;span class="s"&gt;"end"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;mat-stroked-button&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"primary"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;mat-dialog-close&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Cancel
  &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="ni"&gt;&amp;amp;nbsp;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;mat-raised-button&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/mat-dialog-actions&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Our form would then look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1g5defkrlpkqkzao5z58.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1g5defkrlpkqkzao5z58.png" alt="Form image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;idea&lt;/strong&gt; is to prevent user seeing this form before all the data is loaded. We could find solution for that using the Angular &lt;strong&gt;Directive&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Directive&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;[relativeLoader]&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RelativeLoaderDirective&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;OnInit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OnChanges&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;HTMLElement&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Input&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Renderer2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ElementRef&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// create loader&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;ngOnInit&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="nf"&gt;ngOnChanges&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createSimpleLoader&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// execute create loader&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loading&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// hide the first element in the parent div containing directive&lt;/span&gt;
      &lt;span class="c1"&gt;// this should always be a component you want to replace with&lt;/span&gt;
      &lt;span class="c1"&gt;// the loader we are making&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nativeElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstChild&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;display&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nativeElement&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nativeElement&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;nativeElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstChild&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;display&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;block&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;createSimpleLoader&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/** add some style to the loader wrapper */&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;display&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;flex&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;flex-direction&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;column&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;justify-content&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;center&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;align-items&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;center&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// create loader spinner with custom scss&lt;/span&gt;
    &lt;span class="cm"&gt;/** Format of this loader is:
        &amp;lt;div class="lds-roller"&amp;gt;
            &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;
                &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;
                &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;
                &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;
               &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    */&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ldsRoller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ldsRoller&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lds-roller&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ldsRoller&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ldsRoller&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;SCSS for the loader&lt;/strong&gt; (taken from &lt;a href="https://loading.io/css/" rel="noopener noreferrer"&gt;https://loading.io/css/&lt;/a&gt;)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;

&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;inline-block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;lds-roller&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="mi"&gt;.2s&lt;/span&gt; &lt;span class="nf"&gt;cubic-bezier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="mi"&gt;.5&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="mi"&gt;.5&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;infinite&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transform-origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mh"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-4px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;-4px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation-delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-0&lt;/span&gt;&lt;span class="mi"&gt;.036s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;63px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;63px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation-delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-0&lt;/span&gt;&lt;span class="mi"&gt;.072s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;68px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;56px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation-delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-0&lt;/span&gt;&lt;span class="mi"&gt;.108s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;3&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;71px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;48px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;4&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation-delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-0&lt;/span&gt;&lt;span class="mi"&gt;.144s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;4&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;72px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;5&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation-delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-0&lt;/span&gt;&lt;span class="mi"&gt;.18s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;5&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;71px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;32px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;6&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation-delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-0&lt;/span&gt;&lt;span class="mi"&gt;.216s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;6&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;68px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;24px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;7&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation-delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-0&lt;/span&gt;&lt;span class="mi"&gt;.252s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;7&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;63px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;17px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;8&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;animation-delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-0&lt;/span&gt;&lt;span class="mi"&gt;.288s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.lds-roller&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="nd"&gt;:nth-child&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;8&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;:after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;56px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="nt"&gt;lds-roller&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;0&lt;/span&gt;&lt;span class="nv"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0deg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;100&lt;/span&gt;&lt;span class="nv"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;360deg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;&lt;strong&gt;IMPORTANT STUFF!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In order for this to work, you should provide this format of the HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;relativeLoader&lt;/span&gt; &lt;span class="na"&gt;[loading]=&lt;/span&gt;&lt;span class="s"&gt;"your_loading_indicator"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;content-you-want-to-replace-with-loader&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The way it works:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Directive&lt;/strong&gt; will find reference the parent it refers to. It will find the first child which is the first div, It will &lt;strong&gt;hide&lt;/strong&gt; it and add the loader at the end of the parent element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's update our HTML&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;mat-dialog-title&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  Choose suit setup
&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;mat-dialog-content&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;relativeLoader&lt;/span&gt; &lt;span class="na"&gt;[loading]=&lt;/span&gt;&lt;span class="s"&gt;"isLoading === 'loading'"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;[formGroup]=&lt;/span&gt;&lt;span class="s"&gt;"starkForm"&lt;/span&gt; &lt;span class="na"&gt;(submit)=&lt;/span&gt;&lt;span class="s"&gt;"onSubmit()"&lt;/span&gt; &lt;span class="na"&gt;fxLayout=&lt;/span&gt;&lt;span class="s"&gt;"column"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;mat-form-field&lt;/span&gt; &lt;span class="na"&gt;appearance=&lt;/span&gt;&lt;span class="s"&gt;"fill"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;mat-label&amp;gt;&lt;/span&gt;Select suit type&lt;span class="nt"&gt;&amp;lt;/mat-label&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;mat-select&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"selectSuitType"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;mat-option&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let suit of data.suits"&lt;/span&gt; &lt;span class="na"&gt;[value]=&lt;/span&gt;&lt;span class="s"&gt;"suit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
              {{ suit.type }}
            &lt;span class="nt"&gt;&amp;lt;/mat-option&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;/mat-select&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/mat-form-field&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;mat-form-field&lt;/span&gt; &lt;span class="na"&gt;appearance=&lt;/span&gt;&lt;span class="s"&gt;"fill"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;mat-label&amp;gt;&lt;/span&gt;Select color&lt;span class="nt"&gt;&amp;lt;/mat-label&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;mat-select&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"selectColor"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;mat-option&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let color of data.colors"&lt;/span&gt; &lt;span class="na"&gt;[value]=&lt;/span&gt;&lt;span class="s"&gt;"color"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
              {{ color.key }}
            &lt;span class="nt"&gt;&amp;lt;/mat-option&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;/mat-select&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/mat-form-field&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;mat-form-field&lt;/span&gt; &lt;span class="na"&gt;appearance=&lt;/span&gt;&lt;span class="s"&gt;"fill"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;mat-label&amp;gt;&lt;/span&gt;Select reactor type&lt;span class="nt"&gt;&amp;lt;/mat-label&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;mat-select&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"selectReactorType"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;mat-option&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let reactor of data.reactors"&lt;/span&gt; &lt;span class="na"&gt;[value]=&lt;/span&gt;&lt;span class="s"&gt;"reactor"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
              {{ reactor.type }}
            &lt;span class="nt"&gt;&amp;lt;/mat-option&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;/mat-select&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/mat-form-field&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/mat-dialog-content&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;mat-dialog-actions&lt;/span&gt; &lt;span class="na"&gt;align=&lt;/span&gt;&lt;span class="s"&gt;"end"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;mat-stroked-button&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"primary"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;mat-dialog-close&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Cancel
  &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="ni"&gt;&amp;amp;nbsp;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;mat-raised-button&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Create&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/mat-dialog-actions&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Add the end we should get something like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsovvmfhrz22lmh0vb2ks.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsovvmfhrz22lmh0vb2ks.gif" alt="Loading gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, the only thing to worry about is that you have a &lt;strong&gt;class member&lt;/strong&gt; that will control the loading state. But, If you use the provided template you should be able to reuse this loader directive across entire application.&lt;/p&gt;

&lt;h2&gt;
  
  
  🙏 THANK YOU FOR READING!&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Please leave a comment, tell me about you, about your work, comment your thoughts, connect with me! &lt;/p&gt;

&lt;p&gt;☕ SUPPORT ME AND KEEP ME FOCUSED!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ko-fi.com/Z8Z33D1HJ" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.ko-fi.com%2Fcdn%2Fkofi4.png%3Fv%3D2" alt="Buy Me a Coffee at ko-fi.com"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have a nice time hacking! 😊&lt;/p&gt;

</description>
      <category>angular</category>
      <category>typescript</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Replace Switch statement with Record - Typescript</title>
      <dc:creator>devlazar</dc:creator>
      <pubDate>Sun, 13 Mar 2022 13:20:59 +0000</pubDate>
      <link>https://dev.to/devlazar/replace-switch-statement-with-record-typescript-1e3m</link>
      <guid>https://dev.to/devlazar/replace-switch-statement-with-record-typescript-1e3m</guid>
      <description>&lt;p&gt;Table Of Contents&lt;br&gt;
        * 📢ANNOUNCEMENT&lt;br&gt;
        * 🚀INTRO&lt;br&gt;
        * ⚙IMPLEMENTATION&lt;br&gt;
        * 👨🏻‍💻CODESANDBOX&lt;br&gt;
        * 🤔CONCLUSION&lt;br&gt;
        * 🙏THANK YOU&lt;/p&gt;
&lt;h2&gt;
  
  
  📢 ANNOUNCEMENT! &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hello coding dudes and dudesses! Hope you are all well and healthy. It's been quite a difficult time around the globe. I haven't been active for some time. I want to announce that I will communicate with you (through blogs) more often and try to tackle coding, engineering and business with you. Without further ado, let's get into it! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/r4SG84QtRlW0g/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/r4SG84QtRlW0g/giphy.gif" alt="journey"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  🚀 INTRO &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;So, you probably came across a situation where you have something like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someVariable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;someValue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
        &lt;span class="p"&gt;....&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;someOtherValue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="p"&gt;....&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;somethingElse&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="p"&gt;....&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;You probably did, right? Well, there is nothing wrong about this, It is perfectly correct way of replacing the If statement. But we can notice that this can also get a bit hard to follow and manage. With the power of TypeScript we can actually make this even simpler.&lt;/p&gt;
&lt;h2&gt;
  
  
  ⚙ [IMPLEMENTATION] &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Let's consider that each case within the switch statement usually and in the best case has three lines of code.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;valueToCompareWith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;       &lt;span class="c1"&gt;//first line&lt;/span&gt;
      &lt;span class="nf"&gt;someFunctionToExecute&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;//line two&lt;/span&gt;
      &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                     &lt;span class="c1"&gt;//third line&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
We have an assignment:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We should fetch some &lt;strong&gt;financial&lt;/strong&gt; or &lt;strong&gt;product&lt;/strong&gt; data using two different functions (handlers) that someone provided for us. Let's say getFinancialData() and getProductData(). &lt;/li&gt;
&lt;li&gt;For this occasion we are currently using the same indicator, let's call it &lt;strong&gt;dataHandlerIndicator&lt;/strong&gt; and it will be of type 'financial' | 'product'.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's make a switch statement for this example&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;DataType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;financial&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;product&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dataHandlerFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dataHandlerIndicator&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;DataType&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dataHandlerIndicator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;financial&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
         &lt;span class="nf"&gt;getFinancialData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
         &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;product&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
         &lt;span class="nf"&gt;getProductData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
         &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; 


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;So, for these two different DataType types we have 6 lines of code handling it and making it fairly easy to read. If we had 3 types we would have 9 lines of code, and for 10 different data types, well we all understand maths, we will have ~ 30 lines of code, maybe even more if we add some additional logic to the case statement.&lt;/p&gt;

&lt;p&gt;Let's simplify this by using Record!&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// functions to be called&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getFinancialData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Fetch financial data...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getProductData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Fetch product data...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// end functions to be called ...&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;DataType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;financial&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;product&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getDataSelector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;DataType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;financial&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;getFinancialData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;product&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;getProductData&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dataHandlerFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dataHandlerIndicator&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;DataType&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;getDataSelector&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;dataHandlerIndicator&lt;/span&gt;&lt;span class="p"&gt;]()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;dataHandlerFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;product&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 'Fetch product data...'&lt;/span&gt;
&lt;span class="nf"&gt;dataHandlerFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;financial&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 'Fetch financial data...'&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;TRY OUT THE CODESANDBOX EXAMPLE&lt;/strong&gt; &lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/replace-switch-statement-with-record-typescript-usq1fe"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  🤔 CONCLUSION &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Now, we can see that with the Record we have two lines of code describing the functions that will be called based on the DataType key value, and we have one line &lt;code&gt;getDataSelector[dataHandlerIndicator]()&lt;/code&gt; that will call corresponding function based on the dataHandlerIndicator we pass to the function. Pretty neat, right!? &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We reduced number of lines&lt;/li&gt;
&lt;li&gt;Our code is much more readable&lt;/li&gt;
&lt;li&gt;In order to add additional functionality, just update the Record with the new (key, value) pair, and that's it, you have a new selector for fetching new data based on the data type selector.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🙏 THANK YOU FOR READING!&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Please leave a comment, tell me about you, about your work, comment your thoughts, connect with me! &lt;/p&gt;

&lt;p&gt;☕ SUPPORT ME AND KEEP ME FOCUSED!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ko-fi.com/Z8Z33D1HJ" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.ko-fi.com%2Fcdn%2Fkofi4.png%3Fv%3D2" alt="Buy Me a Coffee at ko-fi.com"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have a nice time hacking! 😊&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>BUILD THE REST API USING PYTHON DJANGO - PART 4 🐍</title>
      <dc:creator>devlazar</dc:creator>
      <pubDate>Mon, 22 Feb 2021 19:11:43 +0000</pubDate>
      <link>https://dev.to/devlazar/build-the-rest-api-using-python-django-part-4-nlp</link>
      <guid>https://dev.to/devlazar/build-the-rest-api-using-python-django-part-4-nlp</guid>
      <description>&lt;p&gt;Table Of Contents&lt;br&gt;
        * 🤓INTRO&lt;br&gt;
        * 🔗URLS&lt;br&gt;
        * 👨🏻‍💻SERIALIZERS&lt;br&gt;
        * 👁‍🗨VIEWS&lt;br&gt;
        * 🗺MAP URL&lt;br&gt;
        * 1️⃣GET SPECIFIC RECORD&lt;br&gt;
        * 📣OUTRO&lt;br&gt;
        * 🙏THANK YOU&lt;/p&gt;
&lt;h2&gt;
  
  
  🤓 INTRO &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hello, dear hackers! Welcome to yet another blog article on "Building the REST API with Python Django". I really appreciate your interest in these kinds of articles, and I am really happy that I can help you learn something new.&lt;/p&gt;

&lt;p&gt;If you missed the previous article, check it out:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;div class="ltag__link__content"&gt;
    &lt;div class="missing"&gt;
      &lt;h2&gt;Article No Longer Available&lt;/h2&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Everything I do in this article and upcoming articles will be pushed to the repository on my GitHub:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/devlazar95" rel="noopener noreferrer"&gt;
        devlazar95
      &lt;/a&gt; / &lt;a href="https://github.com/devlazar95/PythonDjangoTutorial" rel="noopener noreferrer"&gt;
        PythonDjangoTutorial
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      This is an official repository of the Codespresso Dev.to tutorial, regarding the "Building the REST API using Python Django" series.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;PythonDjangoTutorial&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;This is an official repository of the Codespresso Dev.to tutorial, regarding the "Building the REST API using Python Django" series.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;HOW TO RUN PROJECT&lt;/h1&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Setup you PostgreSQL database (name: company)&lt;/li&gt;
&lt;li&gt;Edit settings.py and specify DATABASES name to company&lt;/li&gt;
&lt;li&gt;Pull the code from this repository&lt;/li&gt;
&lt;li&gt;Open it up in the PyCharm&lt;/li&gt;
&lt;li&gt;Open terminal and execute &lt;strong&gt;pip install -r requirements.txt&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;strong&gt;python manage.py migrate&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;strong&gt;python manage.py runserver&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/devlazar95/PythonDjangoTutorial" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;Today, we are writing methods for GETting all the data from an API as well as GETting the specific record by record id.&lt;/p&gt;

&lt;p&gt;Please feel free to connect with me via &lt;a href="https://twitter.com/lazar_dev" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/codespressoweb/" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt; or &lt;a href="https://www.linkedin.com/in/lazar-stankovic-44a199177/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's start! 🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  🔗 URLS &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;We already have our urls.py inside our company folder. But what we want to achieve is to make our API URLs map as follow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://127.0.0.1:8000/api/" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/api/&lt;/a&gt; - &lt;strong&gt;BASE URL&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://127.0.0.1:8000/api/employee/" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/api/employee/&lt;/a&gt; - &lt;strong&gt;Return data for all employees in the database&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://127.0.0.1:8000/api/employee/:id" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/api/employee/:id&lt;/a&gt; - &lt;strong&gt;Manipulate specific employee&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://127.0.0.1:8000/api/sector/" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/api/sector/&lt;/a&gt; - &lt;strong&gt;Return data for all sectors in the database&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://127.0.0.1:8000/api/sector/:id" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/api/sector/:id&lt;/a&gt; - &lt;strong&gt;Manipulate specific sector&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://127.0.0.1:8000/api/project/" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/api/project/&lt;/a&gt; - &lt;strong&gt;Return data for all project in the database&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://127.0.0.1:8000/api/project/:id" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/api/project/:id&lt;/a&gt; - &lt;strong&gt;Manipulate specific sector&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To make all routes map into /api/... we will create another file inside our API folder, name it urls.py&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx0x5ne6azf2l28j5onzl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx0x5ne6azf2l28j5onzl.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before we proceed with this file, we need to create our serializer and views&lt;/p&gt;

&lt;h2&gt;
  
  
  👨🏻‍💻 SERIALIZERS &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Serializers allow complex data such as querysets and model instances to be converted to native Python datatypes that can then be easily rendered into JSON, XML, or other content types. Serializers also provide deserialization, allowing parsed data to be converted back into complex types, after first validating the incoming data.&lt;/p&gt;

&lt;p&gt;The serializers in the REST framework work very similarly to Django's Form and ModelForm classes. We provide a Serializer class which gives you a powerful, generic way to control the output of your responses, as well as a ModelSerializer class which provides a useful shortcut for creating serializers that deal with model instances and querysets.&lt;/p&gt;

&lt;p&gt;In our serializers.py add the following code (note that I omitted the code regarding UserSerializer and GroupSerializer):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;company.API.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Employee&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EmployeeSerializer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serializers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ModelSerializer&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Employee&lt;/span&gt;
        &lt;span class="n"&gt;fields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__all__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means that we will serialize our Model &lt;strong&gt;Employee&lt;/strong&gt; and include all the fields that our model offers.&lt;/p&gt;

&lt;h2&gt;
  
  
  👁‍🗨 VIEWS &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Each view we create will handle specific logic and will map the response with the specific route. Let's create our first view, which will get all the data regarding employees.&lt;/p&gt;

&lt;p&gt;In your views.py file add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;company.API.serializers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;UserSerializer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GroupSerializer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EmployeeSerializer&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;company.API.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Employee&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rest_framework.response&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Response&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rest_framework.views&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;APIView&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EmployeeList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;APIView&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    List all employees
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Employee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;serializer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;EmployeeSerializer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;many&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serializer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🗺 MAP URL &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Before we add some code to the newly created urls.py, go to the urls.py file inside the company folder, and in the urlpatterns block add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;api/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;include&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;company.API.urls&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This part of the code will consider the &lt;a href="http://127.0.0.1:8000/api/" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/api/&lt;/a&gt; - the base URL - but that path will map all the paths inside our newly created urls.py.&lt;/p&gt;

&lt;p&gt;Now, we have our Employee &lt;strong&gt;serializer&lt;/strong&gt; and Employee &lt;strong&gt;View&lt;/strong&gt;, we need a specific endpoint that will map our response data.&lt;/p&gt;

&lt;p&gt;In the newly created urls.py, add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;.&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;views&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.urls&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rest_framework.urlpatterns&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;format_suffix_patterns&lt;/span&gt;

&lt;span class="n"&gt;urlpatterns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;employee/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;views&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;EmployeeList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;as_view&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;employees&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;urlpatterns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;format_suffix_patterns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;urlpatterns&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will map our EmployeeList view response to &lt;a href="http://127.0.0.1:8000/api/employee/" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/api/employee/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we should be ready to get the data from the server (please use your admin panel to add some data for employees before proceeding).&lt;/p&gt;

&lt;p&gt;Run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py runserver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Click &lt;a href="http://127.0.0.1:8000/api/employee/" rel="noopener noreferrer"&gt;here&lt;/a&gt; to see the result in your browser or manually type in your URL bar &lt;code&gt;http://127.0.0.1:8000/api/employee/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Since I have only one record in the database, here is my response:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6njmnhqmgpwb1ue55sv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6njmnhqmgpwb1ue55sv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations! 🎉 You created your first GET request, you could also send the request using the Postman, for now, I will stick to the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  1️⃣ GET SPECIFIC RECORD &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Similarly, when we want to get the specific record by the unique identifier, we define our view that we will name EmployeeDetails, and after that, we map our view to the specific URL.&lt;/p&gt;

&lt;p&gt;Here is the view for getting specific Employee record by the unique identifier&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EmployeeDetails&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;APIView&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Retrieve an employee instance&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pk&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Employee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pk&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;pk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="n"&gt;Http404&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pk&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;employee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;serializer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;EmployeeSerializer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serializer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we are using get_object function where we pass the primary key of an instance we are requesting. We have a try-except block of code, where we determine if such an instance exists, or if it does not, we raise an error. An Http404 error is imported as &lt;code&gt;from django.http import Http404&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;Now, we should map our URL, add the following code to the urlpatterns inside the newly created urls.py file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;employee/&amp;lt;slug:pk&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;views&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;EmployeeDetails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;as_view&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;employee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok, we should be ready to retrieve the specific data for a single Employee instance. First, you need a primary key, if you execute &lt;code&gt;http://127.0.0.1:8000/api/employee/&lt;/code&gt; you will see that each employee has an employee_id attribute, copy one of the employee_ids and execute this route &lt;code&gt;https://127.0.0.1:8000/api/employee/paste_your_employee_id_here&lt;/code&gt; you should GET a single instance with the specific employee_id you requested.&lt;/p&gt;

&lt;p&gt;Here is mine 👽&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs69mooarofwz4opvn3vk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs69mooarofwz4opvn3vk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  📣 OUTRO &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;So, we created views for getting all employees' data and for getting a single employee data. The logic is the same for the Project and Sector model. I encourage you to try, and write those &lt;strong&gt;views&lt;/strong&gt;, &lt;strong&gt;serializers&lt;/strong&gt; and &lt;strong&gt;urls&lt;/strong&gt; by yourself, but If you get stuck, you can always look for the solution on my GitHub. In the next article, we will create the POST and PUT methods.&lt;/p&gt;

&lt;h1&gt;
  
  
  🙏 THANK YOU FOR READING!&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Please leave a comment, tell me about you, about your work, comment your thoughts, connect with me! &lt;/p&gt;

&lt;p&gt;☕ SUPPORT ME AND KEEP ME FOCUSED!&lt;br&gt;
&lt;a href="https://ko-fi.com/Z8Z33D1HJ" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.ko-fi.com%2Fcdn%2Fkofi4.png%3Fv%3D2" alt="Buy Me a Coffee at ko-fi.com"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have a nice time hacking! 😊&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>django</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>BUILD THE REST API USING PYTHON DJANGO - PART 3 🐍</title>
      <dc:creator>devlazar</dc:creator>
      <pubDate>Sun, 21 Feb 2021 13:07:39 +0000</pubDate>
      <link>https://dev.to/devlazar/build-the-rest-api-using-python-django-part-3-16c</link>
      <guid>https://dev.to/devlazar/build-the-rest-api-using-python-django-part-3-16c</guid>
      <description>&lt;p&gt;Table Of Contents&lt;br&gt;
        * 🤓INTRO&lt;br&gt;
        * 🧠MODELS&lt;br&gt;
        * 🖖🏻HOW DO WE TRANSLATE RELATIONSHIPS&lt;br&gt;
        * 💃🏻MODELS&lt;br&gt;
        * 👔EMPLOYEE MODEL&lt;br&gt;
        * 🏢SECTOR&lt;br&gt;
        * 📖PROJECT&lt;br&gt;
        * 💼EXPOSE MODELS TO ADMIN PANEL&lt;br&gt;
        * 👨🏻‍💻CODE&lt;br&gt;
        * 🙏THANK YOU&lt;/p&gt;
&lt;h2&gt;
  
  
  🤓 INTRO &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hello, hackers! I hope you are all having a great weekend, it is a beautiful Sunday, and let's complete this week with another part of the "Building the REST API using Python Django" series. &lt;/p&gt;

&lt;p&gt;If you haven't read the previous chapter, it's about setting up the environment and the project.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;div class="ltag__link__content"&gt;
    &lt;div class="missing"&gt;
      &lt;h2&gt;Article No Longer Available&lt;/h2&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Please feel free to connect with me via &lt;a href="https://twitter.com/lazar_dev" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/codespressoweb/" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt; or &lt;a href="https://www.linkedin.com/in/lazar-stankovic-44a199177/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's start! 🚀&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/U4DswrBiaz0p67ZweH/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/U4DswrBiaz0p67ZweH/giphy.gif" alt="dance"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🧠 MODELS &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;We start with an image from the previous post, our ER diagram.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7btoi0ylt64z7u11hg4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7btoi0ylt64z7u11hg4.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each &lt;strong&gt;entity&lt;/strong&gt; represented with the rectangular shape is a &lt;strong&gt;model&lt;/strong&gt;, a class that has attributes that are represented by the oval shape.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Relationships&lt;/strong&gt; are represented by the rhomboid shapes and are crucial for determining how the &lt;strong&gt;models&lt;/strong&gt; are related.&lt;/p&gt;

&lt;h3&gt;
  
  
  🖖🏻 HOW DO WE TRANSLATE RELATIONSHIPS &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ONE-ON-ONE RELATIONSHIPS&lt;/strong&gt; - For any binary type of relationships let's call it R(1:1) in the ER scheme, we identify the relations S and T that correspond to the &lt;strong&gt;entity&lt;/strong&gt; types participating in the relationship R. We choose one of two relations, let's say relation S, and we include a foreign key that represents a corresponding primary key of the relation T.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ONE-ON-MANY RELATIONSHIPS&lt;/strong&gt; - For any binary type of relationship let's call it R(1:N) in the ER scheme, we identify relation S that participates on the N side of the relationship. In the S we include the foreign key that corresponds to the primary key of the relation T.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MANY-TO-MANY RELATIONSHIPS&lt;/strong&gt; - For any binary type of relationship let's call it R(M:N) in the ER scheme, we create a totally new relation P, so-called &lt;strong&gt;pivot table&lt;/strong&gt;. The P includes the foreign keys corresponding to the primary keys of the relations that represent entity types participating in the relationship R.&lt;/p&gt;

&lt;p&gt;We have two relationships that correspond to ONE-TO-MANY relationships and only one relationship corresponding to MANY-TO-MANY relationships.&lt;/p&gt;

&lt;p&gt;This means that in the EMPLOYEE-SECTOR relationship the corresponding entity type on the N side of the relationship is Employee, which means, it will hold a foreign key to the Sector entity type.&lt;/p&gt;

&lt;p&gt;In the SECTOR-PROJECT relationship, the corresponding entity type on the N side of the relationship is the Project entity type, which means, it will hold a foreign key to the Sector entity type.&lt;/p&gt;

&lt;p&gt;In the EMPLOYEE-PROJECT relationship, we have a MANY-TO-MANY relationship. This means, that a new table, a pivot table, will be created with the foreign keys corresponding to the primary keys of the Employee and the Project entity type, respectively.&lt;/p&gt;

&lt;h3&gt;
  
  
  👔 EMPLOYEE MODEL &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;In the &lt;strong&gt;models.py&lt;/strong&gt; we add the following code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndl3q9t47e2nk6649eok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndl3q9t47e2nk6649eok.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;employee_id&lt;/strong&gt; - is a unique identifier represented by the 128-bit number, it's a self-generated, non-editable field.&lt;br&gt;
&lt;strong&gt;first_name, middle_name, last_name&lt;/strong&gt; - are character fields with specified maximum length and are required&lt;br&gt;
&lt;strong&gt;gender&lt;/strong&gt; - is a character field that is representing the choices for the gender specified by GENDER_CHOICES &lt;br&gt;
&lt;strong&gt;address&lt;/strong&gt; - is a character field representing an address&lt;br&gt;
&lt;strong&gt;salary&lt;/strong&gt; - is a decimal field, with two decimal points and is required&lt;/p&gt;

&lt;p&gt;Now let's make our first migrations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py makemigrations
python manage.py migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In your migrations folder you should see something like this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hqrj4y940vi3gzdltn9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hqrj4y940vi3gzdltn9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  🏢 SECTOR MODEL &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz0ra4wxy949jqzxb7nut.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz0ra4wxy949jqzxb7nut.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  📖 PROJECT MODEL &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq5h2sunj6e06n9288jua.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq5h2sunj6e06n9288jua.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Execute the code for creating another migration and migrate the models.&lt;/p&gt;
&lt;h2&gt;
  
  
  💼 EXPOSE MODELS TO ADMIN PANEL &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;In our &lt;strong&gt;admin.py&lt;/strong&gt; we add the following code&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F810lpaby1gwo92opjqe5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F810lpaby1gwo92opjqe5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's run our server, open it up in the browser, log in, redirect to the admin page &lt;a href="HTTP://127.0.0.1:8000/admin"&gt;HTTP://127.0.0.1:8000/admin&lt;/a&gt; and check if our models are exposed.&lt;/p&gt;

&lt;p&gt;In your browser you should see this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0id5bunm1zmzajgsel43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0id5bunm1zmzajgsel43.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Try adding an employee, project, and sector. You should be able to add the data you want. 🚀 &lt;/p&gt;
&lt;h2&gt;
  
  
  👨🏻‍💻 CODE &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/devlazar95" rel="noopener noreferrer"&gt;
        devlazar95
      &lt;/a&gt; / &lt;a href="https://github.com/devlazar95/PythonDjangoTutorial" rel="noopener noreferrer"&gt;
        PythonDjangoTutorial
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      This is an official repository of the Codespresso Dev.to tutorial, regarding the "Building the REST API using Python Django" series.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;PythonDjangoTutorial&lt;/h1&gt;

&lt;/div&gt;

&lt;p&gt;This is an official repository of the Codespresso Dev.to tutorial, regarding the "Building the REST API using Python Django" series.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;HOW TO RUN PROJECT&lt;/h1&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Setup you PostgreSQL database (name: company)&lt;/li&gt;
&lt;li&gt;Edit settings.py and specify DATABASES name to company&lt;/li&gt;
&lt;li&gt;Pull the code from this repository&lt;/li&gt;
&lt;li&gt;Open it up in the PyCharm&lt;/li&gt;
&lt;li&gt;Open terminal and execute &lt;strong&gt;pip install -r requirements.txt&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;strong&gt;python manage.py migrate&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;strong&gt;python manage.py runserver&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;
  &lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/devlazar95/PythonDjangoTutorial" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;That's it for now, I hope you enjoyed it. In the next chapter, we will set up a new url.py file for an API and write our views. Stay tuned! 👽&lt;/p&gt;

&lt;h1&gt;
  
  
  🙏 THANK YOU FOR READING!&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;References:&lt;br&gt;
School notes...&lt;br&gt;
School books...&lt;/p&gt;

&lt;p&gt;Please leave a comment, tell me about you, about your work, comment your thoughts, connect with me! &lt;/p&gt;

&lt;p&gt;☕ SUPPORT ME AND KEEP ME FOCUSED!&lt;br&gt;
&lt;a href="https://ko-fi.com/Z8Z33D1HJ" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.ko-fi.com%2Fcdn%2Fkofi4.png%3Fv%3D2" alt="Buy Me a Coffee at ko-fi.com"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have a nice time hacking! 😊&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>django</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>BUILD THE REST API USING PYTHON DJANGO - PART 2 🐍</title>
      <dc:creator>devlazar</dc:creator>
      <pubDate>Sat, 20 Feb 2021 16:14:22 +0000</pubDate>
      <link>https://dev.to/devlazar/build-the-rest-api-using-python-django-part-2-2ln3</link>
      <guid>https://dev.to/devlazar/build-the-rest-api-using-python-django-part-2-2ln3</guid>
      <description>&lt;p&gt;Table Of Contents&lt;br&gt;
        * 🤓INTRODUCTION&lt;br&gt;
        * 🧠THE PLAN&lt;br&gt;
        * 📚TERMINOLOGY&lt;br&gt;
        * 🦄ENTITES AND RELATIONSHIPS&lt;br&gt;
        * 🌎CREATE THE PROJECT&lt;br&gt;
        * 🙏THANK YOU&lt;/p&gt;
&lt;h2&gt;
  
  
  🤓 INTRODUCTION &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hello, my dear hackers! Welcome, to the second part of the "Building the REST API with Python Django" series. I hope you are all having a great day, today is a big day, we will start &lt;strong&gt;planning&lt;/strong&gt; and &lt;strong&gt;implementing&lt;/strong&gt; the REST API using Python Django Rest Framework. &lt;/p&gt;

&lt;p&gt;Please feel free to connect with me via &lt;a href="https://twitter.com/lazar_dev" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/codespressoweb/" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt; or &lt;a href="https://www.linkedin.com/in/lazar-stankovic-44a199177/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  🧠 THE PLAN &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Let me explain the plan. Don't worry, I will provide a visual example too 😎 We are going to build the REST API handling the company data for Employees, Sectors, and Projects! Each employee, sector, and project is described with specific attributes that are usually of some significance to the user consuming the data. Let me show you the diagram, and I will describe each &lt;strong&gt;entity&lt;/strong&gt; separately as well as the &lt;strong&gt;relationships&lt;/strong&gt; among them.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn9pmdk18brxqna114bgv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn9pmdk18brxqna114bgv.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
First, let's straight-up our terminology.&lt;/p&gt;
&lt;h3&gt;
  
  
  📚 TERMINOLOGY &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;RELATION&lt;/strong&gt; - the table with rows and columns&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ATTRIBUTE&lt;/strong&gt; - named column of the relation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ATTRIBUTE DOMAIN&lt;/strong&gt; - the set of the allowed values for an attribute&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CARDINALITY&lt;/strong&gt; - Number of data instances (rows) in the relation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RELATION KEY&lt;/strong&gt; - An attribute or a set of attributes that identify each data instance in a unique manner&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PRIMARY KEY&lt;/strong&gt; - A candidate key which is selected to identify each data instance in a unique manner&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;FOREIGN KEY&lt;/strong&gt; - An attribute or a set of attributes getting paired-up with the primary key (candidate key) of some other relation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ENTITY INTEGRITY&lt;/strong&gt; - non of the primary key's attributes can have the value of NULL - no primary key can be NULL&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;REFERENTIAL INTEGRITY&lt;/strong&gt; - Values of the foreign key must be equal by value to the candidate key of the specific data instance in the initial relation, or can have the value of NULL&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  🦄 ENTITES AND RELATIONSHIPS &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Our diagram describes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AN EMPLOYEE ENTITY&lt;/strong&gt; - Each employee, has &lt;strong&gt;attributes&lt;/strong&gt;; The name that is a composite attribute and includes the first name, middle name, and last name. Also, we have, gender, address, salary, and the unique identifier ID.&lt;br&gt;
&lt;strong&gt;THE SECTOR ENTITY&lt;/strong&gt; - Name, Location, and a unique identifier.&lt;br&gt;
&lt;strong&gt;THE PROJECT ENTITY&lt;/strong&gt; - Name Location and a unique identifier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RELATIONSHIP 1&lt;/strong&gt; - The relationship between Employee and the Sector. Each employee works in only one sector, and each sector can have many employees.&lt;br&gt;
&lt;strong&gt;RELATIONSHIP 2&lt;/strong&gt; - The relationship between Sector and Project. Each sector can be in charge of multiple projects but that specific project gets assigned to the specific sector.&lt;br&gt;
&lt;strong&gt;RELATIONSHIP 3&lt;/strong&gt; - The relationship between Employee and the Project. Each employee can work on multiple projects, and each project can have multiple employees working on it.&lt;/p&gt;

&lt;p&gt;So, let's get to business and start creating our project! 🚀&lt;/p&gt;
&lt;h2&gt;
  
  
  🌎 CREATE THE PROJECT &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;We start by creating our project, and we will use the PyCharm GUI to do so.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open up the PyCharm&lt;/li&gt;
&lt;li&gt;Click on create the new project - make sure you have the right base interpreter selected
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflgdgolgf2mgy4bdenhm.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;After the virtual environment is initialized you should see something like this in your project directory tree 
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fulxg4r75lxc2cgj608xm.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Open the terminal at the bottom left in the PyCharm IDE&lt;/li&gt;
&lt;li&gt;Install Django by executing this code
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install django
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Install Django Rest Framework by executing the following code
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install djangorestframework
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Set up a new project with a single application
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;django-admin startproject company .
cd company
django-admin startapp API
cd ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp6bq0zjvxpwh7wind70l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp6bq0zjvxpwh7wind70l.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, we created our &lt;strong&gt;project&lt;/strong&gt;, the CompanyProject, and our &lt;strong&gt;application&lt;/strong&gt; within the &lt;strong&gt;project&lt;/strong&gt; that we named API.&lt;/p&gt;

&lt;p&gt;Let's now install the &lt;strong&gt;psycopg2&lt;/strong&gt; adapter for the PostgreSQL database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install psycopg2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Register the rest framework and our application by navigating to the settings.py file and add this to you INSTALLED_APPS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;INSTALLED_APPS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.admin&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.auth&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.contenttypes&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.sessions&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.messages&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.contrib.staticfiles&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;rest_framework&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;company.API&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go to the pgAdmin and create the new database, I will name my database company, you can name yours as you wish.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4t018sdjt46c74k4t037.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4t018sdjt46c74k4t037.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In your settings.py setup the database&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;DATABASES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;default&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ENGINE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.db.backends.postgresql&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;NAME&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;company&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;USER&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;postgres&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;PASSWORD&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;put_postgre_password_here&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;HOST&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;localhost&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;PORT&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;5432&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create serializers.py inside your API directory. Let's create our user serializer and user group serializer. Add this code to your serializers.py file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib.auth.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Group&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rest_framework&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;serializers&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserSerializer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serializers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HyperlinkedModelSerializer&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;
        &lt;span class="n"&gt;fields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;url&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;username&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;email&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;groups&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GroupSerializer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serializers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HyperlinkedModelSerializer&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Group&lt;/span&gt;
        &lt;span class="n"&gt;fields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;url&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And add this code to the views.py file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.contrib.auth.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Group&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rest_framework&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;viewsets&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rest_framework&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;permissions&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;company.API.serializers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;UserSerializer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GroupSerializer&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserViewSet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewsets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ModelViewSet&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    API endpoint that allows users to be viewed or edited.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;queryset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;order_by&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-date_joined&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;serializer_class&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;UserSerializer&lt;/span&gt;
    &lt;span class="n"&gt;permission_classes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IsAuthenticated&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GroupViewSet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewsets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ModelViewSet&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    API endpoint that allows groups to be viewed or edited.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;queryset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;serializer_class&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GroupSerializer&lt;/span&gt;
    &lt;span class="n"&gt;permission_classes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IsAuthenticated&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside your urls.py add the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;django.urls&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;include&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;rest_framework&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;routers&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;company.API&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;views&lt;/span&gt;

&lt;span class="n"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;routers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DefaultRouter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;users&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;views&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UserViewSet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;groups&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;views&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GroupViewSet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
&lt;/span&gt;&lt;span class="n"&gt;urlpatterns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;include&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;urls&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
    &lt;span class="nf"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;api-auth/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;include&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;rest_framework.urls&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;namespace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;rest_framework&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Execute a migration to sync your database for the first time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see something like this in your terminal:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F772s2y3qmibhbq4x0qij.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F772s2y3qmibhbq4x0qij.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let's create the superuser that we will use to login to our administrator panel.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py createsuperuser --email admin@example.com --username admin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After executing this line you will have to specify your password, you can change your password any time.&lt;/p&gt;

&lt;p&gt;Let's run our project!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py runserver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ovjpk647zwbhmejx2ru.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ovjpk647zwbhmejx2ru.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is it! 🎉 We created our first project, go to your browser, redirect to &lt;a href="HTTP://127.0.0.1:8000/"&gt;HTTP://127.0.0.1:8000/&lt;/a&gt; and you will get your browsable API.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkz0nwnhyfvgzbjiklp7x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkz0nwnhyfvgzbjiklp7x.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is it for now, in our next chapter we will create our models for our company API and views.&lt;/p&gt;

&lt;p&gt;Stay tuned! 🚀&lt;/p&gt;

&lt;h1&gt;
  
  
  🙏 THANK YOU FOR READING!&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;References:&lt;br&gt;
School notes...&lt;br&gt;
School books...&lt;/p&gt;

&lt;p&gt;Please leave a comment, tell me about you, about your work, comment your thoughts, connect with me! &lt;/p&gt;

&lt;p&gt;☕ SUPPORT ME AND KEEP ME FOCUSED!&lt;br&gt;
&lt;a href="https://ko-fi.com/Z8Z33D1HJ" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.ko-fi.com%2Fcdn%2Fkofi4.png%3Fv%3D2" alt="Buy Me a Coffee at ko-fi.com"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have a nice time hacking! 😊&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>django</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>BUILD THE REST API USING PYTHON DJANGO - PART 1 🐍</title>
      <dc:creator>devlazar</dc:creator>
      <pubDate>Fri, 19 Feb 2021 22:08:59 +0000</pubDate>
      <link>https://dev.to/devlazar/build-the-rest-api-using-python-django-part-1-1334</link>
      <guid>https://dev.to/devlazar/build-the-rest-api-using-python-django-part-1-1334</guid>
      <description>&lt;p&gt;Table Of Contents&lt;br&gt;
        * 🤓INTRODUCTION&lt;br&gt;
        * 📦WHAT IS AN API&lt;br&gt;
        * 🕸SEMANTICS OF HTTP METHODS&lt;br&gt;
        * 🤔HTTP METHODS&lt;br&gt;
        * 🤠ABOUT DJANGO &amp;amp; DJANGO REST FRAMEWORK&lt;br&gt;
        * ▶GETTING STARTED&lt;br&gt;
        * 🙏THANK YOU&lt;/p&gt;

&lt;h2&gt;
  
  
  🤓 INTRODUCTION &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hello, my dear hackers! I hope you are all having a great end of the working week. Today we are starting the new series where we are going to learn how to use Python and Django Rest Framework to build the REST &lt;strong&gt;A&lt;/strong&gt;pplication &lt;strong&gt;P&lt;/strong&gt;rogramming &lt;strong&gt;I&lt;/strong&gt;nterface.&lt;/p&gt;

&lt;p&gt;This series requires you to be in a good mood, be prepared to read, and have fun, we learn together! 🎉 &lt;/p&gt;

&lt;p&gt;Please feel free to connect with me via &lt;a href="https://twitter.com/lazar_dev" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/codespressoweb/" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt; or &lt;a href="https://www.linkedin.com/in/lazar-stankovic-44a199177/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's do this!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/ynRrAHj5SWAu8RA002/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ynRrAHj5SWAu8RA002/giphy.gif" alt="happy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  📦 WHAT IS AN API &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;An API stands for an application programming interface. It represents a set of definitions and protocols for building and integrating application software. In other words, it is a way to programmatically interact with a separate software component or resource.&lt;br&gt;
Web services were originally designed to communicate using &lt;strong&gt;SOAP&lt;/strong&gt; or Simple Object Access Protocol. Which is a messaging protocol that sends XML documents over HTTP. But, today, most web-based APIs use the REST - Representational State Transfer - as an architectural style.&lt;/p&gt;

&lt;p&gt;You might ask what the REST actually is?&lt;/p&gt;

&lt;p&gt;REST was formally introduced in 2000 by &lt;a href="https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#fig_5_8" rel="noopener noreferrer"&gt;Roy Fielding in his doctoral dissertation&lt;/a&gt; where he explains the REST architecture in the following manner:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Representational State Transfer (REST) style is an abstraction of the architectural elements within a distributed hypermedia system. REST ignores the details of component implementation and protocol syntax in order to focus on the roles of components, the constraints upon their interaction with other components, and their interpretation of significant data elements. It encompasses the fundamental constraints upon components, connectors, and data that define the basis of the Web architecture, and thus the essence of its behavior as a network-based application.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Benefits of using the REST architecture:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;performance in component interactions, which can be the dominant factor in user-perceived performance and network efficiency;&lt;/li&gt;
&lt;li&gt;scalability&lt;/li&gt;
&lt;li&gt;simplicity of a uniform interface&lt;/li&gt;
&lt;li&gt;modifiability of components to meet changing needs (even while the application is running);&lt;/li&gt;
&lt;li&gt;visibility of communication between components by service agents;&lt;/li&gt;
&lt;li&gt;portability of components by moving program code with the data;&lt;/li&gt;
&lt;li&gt;reliability in the resistance to failure at the system level in the presence of failures within components, connectors, or data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🕸 SEMANTICS OF HTTP METHODS &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Since we are building REST API, specifically HTTP-based REST APIs, the basic structure of the REST APIs is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a base URI, for example &lt;a href="http://my-api.example.com/" rel="noopener noreferrer"&gt;http://my-api.example.com/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;standard &lt;a href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods" rel="noopener noreferrer"&gt;HTTP request methods&lt;/a&gt; (GET, POST, PUT and DELETE)&lt;/li&gt;
&lt;li&gt;a media type that defines state transition data elements. The current representation tells the client how to compose requests for transitions to all the next available application states.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🤔 HTTP METHODS &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  GET
&lt;/h3&gt;

&lt;p&gt;The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.&lt;/p&gt;

&lt;h3&gt;
  
  
  HEAD
&lt;/h3&gt;

&lt;p&gt;The HEAD method asks for a response identical to that of a GET request, but without the response body.&lt;/p&gt;

&lt;h3&gt;
  
  
  POST
&lt;/h3&gt;

&lt;p&gt;The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.&lt;/p&gt;

&lt;h3&gt;
  
  
  PUT
&lt;/h3&gt;

&lt;p&gt;The PUT method replaces all current representations of the target resource with the request payload.&lt;/p&gt;

&lt;h3&gt;
  
  
  DELETE
&lt;/h3&gt;

&lt;p&gt;The DELETE method deletes the specified resource.&lt;/p&gt;

&lt;h3&gt;
  
  
  PATCH
&lt;/h3&gt;

&lt;p&gt;The PATCH method is used to apply partial modifications to a resource.&lt;/p&gt;

&lt;h2&gt;
  
  
  🤠 ABOUT DJANGO &amp;amp; DJANGO REST FRAMEWORK &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.&lt;br&gt;
Django REST framework is a powerful and flexible toolkit for building Web APIs. Some reasons you might want to use the REST framework:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Web browsable API is a huge usability win for your developers.&lt;/li&gt;
&lt;li&gt;Authentication policies including packages for OAuth1a and OAuth2.&lt;/li&gt;
&lt;li&gt;Serialization that supports both ORM and non-ORM data sources.&lt;/li&gt;
&lt;li&gt;Customizable all the way down - just use regular function-based views if you don't need the more powerful features.&lt;/li&gt;
&lt;li&gt;Extensive documentation, and great community support.&lt;/li&gt;
&lt;li&gt;Used and trusted by internationally recognized companies including Mozilla, Red Hat, Heroku, and Eventbrite.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0ogplq9y9rw9rl9y7ss.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg0ogplq9y9rw9rl9y7ss.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't give up, we are getting somewhere!&lt;/strong&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  ▶ GETTING STARTED &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  REQUIREMENTS
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.python.org/" rel="noopener noreferrer"&gt;Python&lt;/a&gt; - v3.9.2&lt;br&gt;
&lt;a href="https://www.postgresql.org/" rel="noopener noreferrer"&gt;PostgreSQL&lt;/a&gt; - v12.2 (pgAdmin 4 -optional)&lt;br&gt;
Django - v3.1.7&lt;br&gt;
Django Rest Framework - v3.12.2&lt;br&gt;
psycopg2 - v2.8.6&lt;/p&gt;

&lt;p&gt;You will also need the IDE of your choice, I am using the &lt;a href="https://www.jetbrains.com/pycharm/" rel="noopener noreferrer"&gt;Jet Brains PyCharm Community Edition&lt;/a&gt; and I strongly recommend it!&lt;/p&gt;

&lt;p&gt;❗ You should probably add Python to your Environment variables if you don't have it already&lt;/p&gt;

&lt;p&gt;So, this is what you need to be familiar with, of course, an actual topic of the REST paradigm, as well as HTTP, is much, much broader. Because of that, I &lt;strong&gt;encourage&lt;/strong&gt; you to read a little bit more about it. Here are some useful links:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#fig_5_8" rel="noopener noreferrer"&gt;REST&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP" rel="noopener noreferrer"&gt;HTTP&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next chapter, we are going to &lt;strong&gt;create the project&lt;/strong&gt;, setup &lt;strong&gt;Django&lt;/strong&gt; and &lt;strong&gt;Django rest framework&lt;/strong&gt;, and start writing our models, views, serializers, etc...&lt;/p&gt;

&lt;p&gt;Stay tuned! 🚀&lt;/p&gt;

&lt;h1&gt;
  
  
  🙏 THANK YOU FOR READING!&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;References:&lt;br&gt;
School notes...&lt;br&gt;
School books...&lt;/p&gt;

&lt;p&gt;Please leave a comment, tell me about you, about your work, comment your thoughts, connect with me! &lt;/p&gt;

&lt;p&gt;☕ SUPPORT ME AND KEEP ME FOCUSED!&lt;br&gt;
&lt;a href="https://ko-fi.com/Z8Z33D1HJ" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.ko-fi.com%2Fcdn%2Fkofi4.png%3Fv%3D2" alt="Buy Me a Coffee at ko-fi.com"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have a nice time hacking! 😊&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>django</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>Elementary Data Structures with JavaScript - Binary trees - PART 3🚀</title>
      <dc:creator>devlazar</dc:creator>
      <pubDate>Wed, 17 Feb 2021 19:01:57 +0000</pubDate>
      <link>https://dev.to/devlazar/elementary-data-structures-with-javascript-binary-trees-part-3-7f8</link>
      <guid>https://dev.to/devlazar/elementary-data-structures-with-javascript-binary-trees-part-3-7f8</guid>
      <description>&lt;p&gt;Table Of Contents&lt;br&gt;
        * 🤓 INTRODUCTION&lt;br&gt;
        * 🌴BREADTH-FIRST SEARCH&lt;br&gt;
        * 🌊DEPTH-FIRST SEARCH&lt;br&gt;
        * 👨🏻‍💻CODE&lt;br&gt;
        * 🙏 THANK YOU&lt;/p&gt;
&lt;h2&gt;
  
  
  🤓 INTRODUCTION &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hello, my dear coders! I hope you are all having a great day 🚀&lt;br&gt;
Today, we are going to explore ways to traverse a tree with algorithms designed to optimize the search and traversal. Of course, for our implementation, we will use Vanilla JavaScript.&lt;/p&gt;

&lt;p&gt;If you missed the previous part of this article you can check it out right here:&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;div class="ltag__link__content"&gt;
    &lt;div class="missing"&gt;
      &lt;h2&gt;Article No Longer Available&lt;/h2&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Please feel free to connect with me via &lt;a href="https://twitter.com/lazar_dev"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/codespressoweb/"&gt;Instagram&lt;/a&gt; or &lt;a href="https://www.linkedin.com/in/lazar-stankovic-44a199177/"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🌴 BREADTH-FIRST SEARCH &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Breadth-first search is characterized by the fact that it focuses on every item, from left to right, on every level before moving to the next.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3Vy0tgi6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgpfue4cxr851zdtxdp7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3Vy0tgi6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgpfue4cxr851zdtxdp7.png" alt="Alt Text" width="880" height="515"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  🌊 DEPTH-FIRST SEARCH &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The strategy followed by depth-first search is, as its name implies, to search “deeper” in the three whenever possible. Depth-first searches are more concerned with completing a traversal down the whole side of the tree to the leaves than completing every level. There are three main ways to handle this, preOrder, postOrder, and inOrder but they’re just very slight modifications of each other to change the output order.&lt;/p&gt;
&lt;h3&gt;
  
  
  1️⃣ PREORDER
&lt;/h3&gt;

&lt;p&gt;What preorder does, it processes the root, traverses the left subtree, and after that, traverses the right subtree.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Oopfy3Ms--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ku0vfzzby484j11ysolv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Oopfy3Ms--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ku0vfzzby484j11ysolv.png" alt="Alt Text" width="880" height="575"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2️⃣ POSTORDER
&lt;/h3&gt;

&lt;p&gt;First, we traverse the left subtree, after that, traverse the right subtree and, process the root.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--35I11tnF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xyr9id3kq1wnapoifo1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--35I11tnF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xyr9id3kq1wnapoifo1.png" alt="Alt Text" width="880" height="575"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  3️⃣ INORDER
&lt;/h2&gt;

&lt;p&gt;First, we traverse the left subtree of the root, then we process the root and after that, we traverse the right subtree of the root.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nxrDJAS8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ckv1h2o2j9g3rs92ivi3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nxrDJAS8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ckv1h2o2j9g3rs92ivi3.png" alt="Alt Text" width="880" height="575"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  👨🏻‍💻 CODE &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Here is the code! 🚀&lt;br&gt;
&lt;iframe src="https://jsfiddle.net/codespresso/3rw0qbhf/77//embedded/js,result,html,css//dark" width="100%" height="600"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  🙏 THANK YOU FOR READING!&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;References:&lt;br&gt;
School notes...&lt;br&gt;
School books...&lt;/p&gt;

&lt;p&gt;Please leave a comment, tell me about you, about your work, comment your thoughts, connect with me! &lt;/p&gt;

&lt;p&gt;☕ SUPPORT ME AND KEEP ME FOCUSED!&lt;br&gt;
&lt;a href="https://ko-fi.com/Z8Z33D1HJ"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IT81Gxvw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.ko-fi.com/cdn/kofi4.png%3Fv%3D2" alt="Buy Me a Coffee at ko-fi.com" width="606" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have a nice time hacking! 😊&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>programming</category>
      <category>codequality</category>
    </item>
    <item>
      <title>Elementary Data Structures with JavaScript - Binary trees - PART 2🚀</title>
      <dc:creator>devlazar</dc:creator>
      <pubDate>Tue, 16 Feb 2021 13:25:15 +0000</pubDate>
      <link>https://dev.to/devlazar/elementary-data-structures-with-javascript-binary-trees-part-2-1pl6</link>
      <guid>https://dev.to/devlazar/elementary-data-structures-with-javascript-binary-trees-part-2-1pl6</guid>
      <description>&lt;p&gt;Table Of Contents&lt;br&gt;
        * 🤓 INTRODUCTION&lt;br&gt;
        * 0️⃣1️⃣ ABOUT BINARY SEARCH TREES&lt;br&gt;
        * ⭕ CREATE A NODE&lt;br&gt;
        * 🔎BINARY SEARCH TREE&lt;br&gt;
        * 🔍FIND AN ELEMENT&lt;br&gt;
        * 👨🏻‍💻CODE&lt;br&gt;
        * 🙏 THANK YOU&lt;/p&gt;
&lt;h2&gt;
  
  
  🤓 INTRODUCTION &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Welcome, my dear hackers!🚀 Welcome to yet another blog article about elementary data structures. &lt;/p&gt;

&lt;p&gt;If you missed the previous article where we describe the Binary trees, you can check it out right here:&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;div class="ltag__link__content"&gt;
    &lt;div class="missing"&gt;
      &lt;h2&gt;Article No Longer Available&lt;/h2&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Today, we will show how to implement the binary search tree. We will concentrate on the implementation with a bit of theoretical explanation in the beginning. 🚀&lt;/p&gt;

&lt;p&gt;Please feel free to connect with me via &lt;a href="https://twitter.com/lazar_dev"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.instagram.com/codespressoweb/"&gt;Instagram&lt;/a&gt; or &lt;a href="https://www.linkedin.com/in/lazar-stankovic-44a199177/"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  0️⃣1️⃣ ABOUT BINARY SEARCH TREES &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Basic operations on a binary search tree take time proportional to the height of the tree. For a complete binary tree with n nodes, such operations run in the O(logn) worst-case time.&lt;br&gt;
If the tree is a linear chain of n nodes, however, the same operations take O(n) worst-case time. &lt;br&gt;
In practice, we can’t always guarantee that binary search trees are built randomly, but we can design variations of binary search trees with good guaranteed&lt;br&gt;
worst-case performance on basic operations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A binary search tree&lt;/strong&gt; is organized, as the name suggests, in a binary tree, that we discussed in the previous chapter. There, we concluded that we can represent such a tree by a linked data structure in which each node is an object. In addition to a &lt;strong&gt;key&lt;/strong&gt; and &lt;strong&gt;satellite&lt;/strong&gt; data, each node contains attributes &lt;strong&gt;left&lt;/strong&gt;, &lt;strong&gt;right&lt;/strong&gt; and a pointer that points to the nodes corresponding to its left child, its right child, and its parent, respectively. So, if a child or the parent is missing, the appropriate attribute contains the value of &lt;strong&gt;NULL&lt;/strong&gt;. The &lt;strong&gt;root&lt;/strong&gt; node is the only node in the tree whose parent is &lt;strong&gt;NULL&lt;/strong&gt;. The keys in a &lt;strong&gt;binary search tree&lt;/strong&gt; are always stored in such a way as to satisfy the binary search tree property.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Let x be a node in a binary search tree. If y is a node in the left subtree of x, then y:key &amp;lt;= x:key. If y is a node in the right subtree of x, then y:key &amp;gt;= x:key.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The binary-search-tree property allows us to print out all the keys in a binary search tree in sorted order by a simple recursive algorithm, called an inorder tree walk. This algorithm is so named because it prints the key of the root of a subtree between printing the values in its left subtree and printing those in its right subtree. (Similarly, a preorder tree walk prints the root before the values in either subtree and a postorder tree walk prints the root after the values in its subtrees.)&lt;/p&gt;

&lt;h2&gt;
  
  
  ⭕ CREATE A NODE &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s85cvEs5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/csk2r8v3bi6k5nc5w1by.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s85cvEs5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/csk2r8v3bi6k5nc5w1by.png" alt="Alt Text" width="716" height="660"&gt;&lt;/a&gt;&lt;br&gt;
As you can see in an image, we have a class BSTNode (Binary Search Tree Node) that has a constructor that takes up an argument of value being assigned to a member class variable value; Also, we have two pointers left and right, that will point to the left child and right child, respectively. The counter is used to control the duplication of the node values. For example, if we try to add another node with the same value as any node in a tree, we just increase the counter but do not add that node to the tree.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔎 BINARY SEARCH TREE &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DCnBCypZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rch2soh75qvjrvht93t9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DCnBCypZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rch2soh75qvjrvht93t9.png" alt="Alt Text" width="880" height="679"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🔍 FIND AN ELEMENT &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ASvFkC9T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hf03nkod42xgzo9hpdze.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ASvFkC9T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hf03nkod42xgzo9hpdze.png" alt="Alt Text" width="880" height="327"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  👨🏻‍💻 CODE &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;BSTNode&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;BST&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;BSTNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newNode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addSide&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;side&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;side&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;side&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newNode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;side&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;addSide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;left&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nx"&gt;addSide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;right&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;found&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;found&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nx"&gt;found&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;found&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Oops! Nothing found!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;binary_search_tree&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;BST&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;binary_search_tree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;binary_search_tree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;binary_search_tree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;binary_search_tree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;221&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;binary_search_tree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;binary_search_tree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;44&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;binary_search_tree&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The expected output should be something like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K77A8YYl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2cnamfs85njao09oir0r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K77A8YYl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2cnamfs85njao09oir0r.png" alt="Alt Text" width="880" height="827"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  🙏 THANK YOU FOR READING!&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Stay tuned for the next chapter of this article where we will implement deletion and traversal logic!&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
School notes...&lt;br&gt;
School books...&lt;/p&gt;

&lt;p&gt;Please leave a comment, tell me about you, about your work, comment your thoughts, connect with me! &lt;/p&gt;

&lt;p&gt;☕ SUPPORT ME AND KEEP ME FOCUSED!&lt;br&gt;
&lt;a href="https://ko-fi.com/Z8Z33D1HJ"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IT81Gxvw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.ko-fi.com/cdn/kofi4.png%3Fv%3D2" alt="Buy Me a Coffee at ko-fi.com" width="606" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have a nice time hacking! 😊&lt;/p&gt;

</description>
      <category>programming</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
