<?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: wizcoderx</title>
    <description>The latest articles on DEV Community by wizcoderx (@wizcoderx).</description>
    <link>https://dev.to/wizcoderx</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%2F2727934%2F834f6c21-3ddc-401a-9fe3-f40c062ed07d.png</url>
      <title>DEV Community: wizcoderx</title>
      <link>https://dev.to/wizcoderx</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wizcoderx"/>
    <language>en</language>
    <item>
      <title>Docker Chapter 1: A Beginner's Introduction to Containerization.</title>
      <dc:creator>wizcoderx</dc:creator>
      <pubDate>Sun, 06 Jul 2025 13:07:29 +0000</pubDate>
      <link>https://dev.to/wizcoderx/docker-chapter-1-a-beginners-introduction-to-containerization-1eaj</link>
      <guid>https://dev.to/wizcoderx/docker-chapter-1-a-beginners-introduction-to-containerization-1eaj</guid>
      <description>&lt;p&gt;As a software developer , I've discovered that Docker has become an indispensable tool in my development workflow. Let me break down what Docker is, why you should use it, and how it revolutionizes traditional software development.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Docker?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Technical Definition:&lt;/strong&gt; Docker is a containerization platform that allows you to package your applications or microservices into lightweight, portable containers. These containers can then be deployed and started (or "spun up") across different environments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple Explanation:&lt;/strong&gt; Think of Docker as a standardized shipping container for your software. Just like how physical shipping containers can be moved from ships to trucks to trains without unpacking, Docker containers can run your application on any system that has Docker installed.&lt;/p&gt;

&lt;p&gt;When you containerize your application, it gets stored in what we call a &lt;strong&gt;container&lt;/strong&gt; (this terminology is crucial in technical communication). You can then distribute this container to clients or team members, and they can simply "UP" or start the services with a single command.&lt;/p&gt;

&lt;p&gt;For example, if you've built a microservice using FastAPI, once someone starts your Docker container, they can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access your API endpoints by sending requests with the required payload&lt;/li&gt;
&lt;li&gt;View the interactive Swagger UI documentation&lt;/li&gt;
&lt;li&gt;Use your service without worrying about local setup complexities&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why Should You Use Docker?
&lt;/h2&gt;

&lt;p&gt;The answer is simple: &lt;strong&gt;efficiency and reliability&lt;/strong&gt;. As developers, we know that life is short, and time spent on complex deployment processes is time taken away from actual development.&lt;/p&gt;

&lt;p&gt;Docker eliminates the "it works on my machine" problem. Once you containerize your application, you can be confident it will run consistently across different environments. This reliability becomes especially important when working with AI/ML applications that often have complex dependency requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages Over Traditional Software Development
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Code Security and Intellectual Property Protection&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Your source code remains secure within the container. Clients receive a packaged application without access to your underlying codebase, reducing concerns about code piracy or intellectual property leaks.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Cross-Platform Compatibility&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Here's where Docker truly shines. Traditional development often faces the challenge: "Will my Linux-developed application run on a Mac?" or "What about Windows compatibility?"&lt;/p&gt;

&lt;p&gt;Docker abstracts away these OS-level differences. Whether you develop on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Linux&lt;/li&gt;
&lt;li&gt;Windows
&lt;/li&gt;
&lt;li&gt;macOS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your containerized application will run consistently across all these platforms. Docker handles the underlying OS dependencies and compatibility issues, so you don't have to worry about platform-specific implementations.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Dependency Management&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Docker bundles your application with all its dependencies, libraries, and runtime requirements. This means no more version conflicts or missing dependencies on deployment machines.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;Scalability and Resource Efficiency&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Containers are lightweight compared to virtual machines, allowing you to run multiple instances of your application efficiently. This is particularly valuable for microservices architectures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Impact
&lt;/h2&gt;

&lt;p&gt;In my experience developing applications, Docker has been a game-changer. AI models often require specific Python versions, CUDA drivers, and various ML libraries. Docker ensures that these complex environments are reproducible and portable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;Docker fundamentals are just the beginning. In my next article &lt;em&gt;Chapter 2&lt;/em&gt;, I'll provide hands-on examples of containerizing a real application developed in fast api, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Writing effective Dockerfiles&lt;/li&gt;
&lt;li&gt;Managing multi-container applications with Docker Compose&lt;/li&gt;
&lt;li&gt;Best practices for production deployments&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you are not aware of fastapi take a look at this article before moving towards &lt;em&gt;Chapter 2&lt;/em&gt; - &lt;a href="https://dev.to/wizcoderx/getting-started-with-fastapi-a-beginners-guide-using-python-1g2a"&gt;Getting Started with FastAPI: A Beginner’s Guide Using Python&lt;/a&gt;&lt;/p&gt;




</description>
      <category>docker</category>
      <category>beginners</category>
      <category>contenizer</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Getting Started with FastAPI: A Beginner’s Guide Using Python 🐍</title>
      <dc:creator>wizcoderx</dc:creator>
      <pubDate>Sun, 01 Jun 2025 13:26:17 +0000</pubDate>
      <link>https://dev.to/wizcoderx/getting-started-with-fastapi-a-beginners-guide-using-python-1g2a</link>
      <guid>https://dev.to/wizcoderx/getting-started-with-fastapi-a-beginners-guide-using-python-1g2a</guid>
      <description>&lt;h1&gt;
  
  
  Introduction to FastAPI
&lt;/h1&gt;

&lt;p&gt;Imagine you're at a restaurant. You tell the waiter your order, and the waiter communicates it to the kitchen and brings back your food. FastAPI works just like that waiter. It is a modern, high-performance web framework for building APIs with Python, letting your app/application talk to other apps/applications efficiently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fastapi.tiangolo.com/" rel="noopener noreferrer"&gt;Official FastAPI Docs&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  So, why FastAPI instead of Flask or Django REST?
&lt;/h2&gt;

&lt;p&gt;Because FastAPI is as fast as Node.js and Go, uses Python type hints for validation, generates automatic docs, and is asynchronous by design. Compared to Flask, it's more scalable out of the box. Unlike Django REST Framework, it's minimal and lightning fast.&lt;/p&gt;

&lt;p&gt;In the real world, FastAPI is used in production by companies building &lt;strong&gt;GenAI backends, microservices, ML model deployment, and startups that need to move fast with clean code and performance in mind.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;To follow along, make sure Python is installed on your system. You can download it from &lt;a href="https://www.python.org/" rel="noopener noreferrer"&gt;python.org&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We'll use a virtual environment (venv) to isolate dependencies — this helps avoid breaking your global packages and keeps the project clean.&lt;/p&gt;

&lt;p&gt;Next, we'll use PyCharm IDE Community Edition, because the community edition is free :) — it offers smart code suggestions, automatic virtual environment detection, and built-in terminal, making Python development smooth and efficient. You can download it from &lt;a href="https://www.jetbrains.com/pycharm/download" rel="noopener noreferrer"&gt;PyCharm Download&lt;/a&gt; and search for &lt;strong&gt;PyCharm Community Edition.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, let's build your first FastAPI app:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a folder named &lt;code&gt;fastapi_intro&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Open PyCharm and create a new Python project inside that folder. OR right-click on the folder and click "open with PyCharm", this will create a &lt;code&gt;main.py&lt;/code&gt; file automatically.&lt;/li&gt;
&lt;li&gt;Open the terminal inside PyCharm which is mostly at the bottom left of the screen and run:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; venv venv
&lt;span class="nb"&gt;source &lt;/span&gt;venv/bin/activate  &lt;span class="c"&gt;# or venv\Scripts\activate on Windows&lt;/span&gt;
pip &lt;span class="nb"&gt;install &lt;/span&gt;fastapi uvicorn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a file named &lt;code&gt;main.py&lt;/code&gt; if it doesn't exist
&lt;/li&gt;
&lt;/ol&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;fastapi&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FastAPI&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FastAPI&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nd"&gt;@app.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;read_root&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;message&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;Hello, FastAPI&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;ol&gt;
&lt;li&gt;Run it using the below command in terminal:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uvicorn main:app &lt;span class="nt"&gt;--reload&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Open your browser and go to &lt;a href="http://127.0.0.1:8000/docs" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/docs&lt;/a&gt; — FastAPI auto-generates interactive Swagger docs! 🎉&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  A Quick Note on BaseModel
&lt;/h2&gt;

&lt;p&gt;Before we jump into the mini project, let's understand this line:&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;pydantic&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BaseModel&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;FastAPI uses Pydantic for data validation. BaseModel lets you define the structure of the data your API expects. When a request is made, FastAPI uses that model to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validate the input (e.g., check if it's an int)&lt;/li&gt;
&lt;li&gt;Parse and document it automatically in the Swagger UI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it as a Python class that ensures your API only accepts clean, structured data — no manual checks needed!&lt;/p&gt;

&lt;p&gt;Think of BaseModel like a blueprint for incoming data — it tells FastAPI exactly what shape the data should be. Just like a form with required fields, it checks the input and throws an error if something's missing or incorrect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mini Project: Simple Calculator API
&lt;/h2&gt;

&lt;p&gt;Let's build a mini calculator with two FastAPI endpoints — one for addition and one for subtraction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step-by-step:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; Installing the correct version of Pydantic is important, so before proceeding with the following step, kindly install Pydantic version 2.&lt;/p&gt;

&lt;p&gt;Run the following in your terminal (inside your virtual environment):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip uninstall pydantic
pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="s2"&gt;"pydantic&amp;lt;2.0.0"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Update your &lt;code&gt;main.py&lt;/code&gt;:
&lt;/li&gt;
&lt;/ol&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;fastapi&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FastAPI&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pydantic&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BaseModel&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FastAPI&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;Numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;number_1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;number_2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;

&lt;span class="nd"&gt;@app.post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/add&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Numbers&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number_1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number_2&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;number_1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number_1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;number_2&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number_2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;result&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;@app.post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/subtract&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;subtract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Numbers&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number_1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number_2&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;number_1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number_1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;number_2&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number_2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;result&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&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;ol&gt;
&lt;li&gt;Run the server again:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uvicorn main:app &lt;span class="nt"&gt;--reload&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Test both endpoints at &lt;a href="http://127.0.0.1:8000/docs" rel="noopener noreferrer"&gt;http://127.0.0.1:8000/docs&lt;/a&gt; using the Swagger UI.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Your input JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"number_1"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"number_2"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&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;Expected output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"number_1"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"number_2"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"result"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"15"&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;If you want an in-depth understanding of the above code, then please read the below; otherwise, jump to the &lt;strong&gt;Challenge&lt;/strong&gt; section.&lt;/p&gt;

&lt;h2&gt;
  
  
  In-Depth Analysis of Code:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. In-depth Explanation (What the Code Does)
&lt;/h3&gt;

&lt;p&gt;This code creates a simple API with FastAPI that exposes two endpoints: one to add and one to subtract two numbers. The &lt;code&gt;FastAPI()&lt;/code&gt; class sets up the web app. Then, using &lt;code&gt;BaseModel&lt;/code&gt; from Pydantic, a class &lt;code&gt;Numbers&lt;/code&gt; is defined which describes the shape of the input data — expecting two integers. When a POST request is made to either &lt;code&gt;/add&lt;/code&gt; or &lt;code&gt;/subtract&lt;/code&gt;, FastAPI automatically parses the JSON input based on &lt;code&gt;Numbers&lt;/code&gt;, validates that &lt;code&gt;number_1&lt;/code&gt; and &lt;code&gt;number_2&lt;/code&gt; are both integers with the help of &lt;code&gt;BaseModel&lt;/code&gt;, and injects the validated data into the corresponding function (add or subtract). The function then performs the calculation and returns a JSON response containing the input values and the result as a string. FastAPI also auto-generates interactive docs based on this setup using Swagger.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Analogy (Line-by-Line Intuition)
&lt;/h3&gt;

&lt;p&gt;Think of building a tiny calculator counter inside a digital restaurant.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;from fastapi import FastAPI&lt;/code&gt;: This is like setting up the front desk where people come in with requests.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;from pydantic import BaseModel&lt;/code&gt;: This brings in the clipboard where we write down what kind of form customers must fill out.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;app = FastAPI()&lt;/code&gt;: You're now opening the restaurant and saying "we're ready to take orders!"&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;class Numbers(BaseModel): ...&lt;/code&gt;: This is the form customers must fill, saying: "Please give me two whole numbers to work with."&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@app.post("/add")&lt;/code&gt;: You're putting up a sign at a counter saying "For addition, hand your form here."&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;def add(numbers: Numbers):&lt;/code&gt;: The chef (your function) picks up the form and sees the numbers written.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;result = numbers.number_1 + numbers.number_2&lt;/code&gt;: The chef does the math using the values from the form.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;return {...}&lt;/code&gt;: The waiter hands back a neat receipt showing the input numbers and the final total.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same goes for the &lt;code&gt;/subtract&lt;/code&gt; counter — it's just a different chef doing subtraction instead of addition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenge:
&lt;/h2&gt;

&lt;p&gt;Now it's your turn!&lt;/p&gt;

&lt;p&gt;Create two more endpoints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;/multiply&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/divide&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Try writing them yourself — and post your versions in the comments section! 💬&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;In the next chapter, we will see how we can use FastAPI with GenAI apps like Gemini API to ask questions and get responses back from it.&lt;/p&gt;

&lt;p&gt;Stay tuned. It's wizcoderx!&lt;/p&gt;

</description>
      <category>python</category>
      <category>fastapi</category>
      <category>api</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
