<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[FastAPI_Day-1]]></title><description><![CDATA[FastAPI_Day-1]]></description><link>https://anshkumarpandey0909.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 13:41:23 GMT</lastBuildDate><atom:link href="https://anshkumarpandey0909.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[🚀 My First Step with FastAPI: Async APIs, Pydantic, and CRUD Basics]]></title><description><![CDATA[Hey devs! 👋
Yesterday marked the beginning of my journey into real-world backend development using FastAPI. I spent time understanding the fundamentals and wanted to document it as a learning log. Hopefully, this helps others getting started too!
🔧...]]></description><link>https://anshkumarpandey0909.hashnode.dev/my-first-step-with-fastapi-async-apis-pydantic-and-crud-basics</link><guid isPermaLink="true">https://anshkumarpandey0909.hashnode.dev/my-first-step-with-fastapi-async-apis-pydantic-and-crud-basics</guid><category><![CDATA[#FastAPI #Python #BackendDevelopment #WebDev #Pydantic #LearningInPublic #OpenSource #AI #SaaS]]></category><dc:creator><![CDATA[Ansh Kumar Pandey]]></dc:creator><pubDate>Sun, 01 Jun 2025 05:09:14 GMT</pubDate><content:encoded><![CDATA[<p>Hey devs! 👋</p>
<p>Yesterday marked the beginning of my journey into real-world backend development using <strong>FastAPI</strong>. I spent time understanding the fundamentals and wanted to document it as a learning log. Hopefully, this helps others getting started too!</p>
<h2 id="heading-fastapi-setup">🔧 FastAPI Setup</h2>
<p>To begin, I installed FastAPI and a production-ready ASGI server:</p>
<pre><code class="lang-plaintext">pip install "fastapi[standard]"
</code></pre>
<h2 id="heading-project-structure-amp-first-endpoint">📂 Project Structure &amp; First Endpoint</h2>
<pre><code class="lang-plaintext">from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def read_root():
    return {"message": "Hello World"}
</code></pre>
<ul>
<li><p><code>@app.get("/")</code>: Defines a GET route.</p>
</li>
<li><p><code>async def</code>: Supports asynchronous calls for high-performance APIs.</p>
</li>
</ul>
<hr />
<h2 id="heading-path-amp-query-parameters">🧩 Path &amp; Query Parameters</h2>
<p>I then learned how to create endpoints with both path and query parameters:</p>
<pre><code class="lang-plaintext">from typing import Optional

@app.get("/greet/")
async def greet_name(name: Optional[str] = "User", age: Optional[int] = 19) -&gt; dict:
    return {"message": f"Hello {name}", "Age": age}
</code></pre>
<ul>
<li>Query parameters appear in URL like: <code>/greet/?name=Ansh&amp;age=19</code></li>
</ul>
<hr />
<h2 id="heading-pydantic-models-serialization-amp-validation">📘 Pydantic Models (Serialization &amp; Validation)</h2>
<p>Pydantic's <code>BaseModel</code> allows us to create structured data models and auto-validates input:</p>
<pre><code class="lang-plaintext">from pydantic import BaseModel

class BookCreateModel(BaseModel):
    title: str
    author: str

@app.post("/create_book", status_code=200)
async def create_book(book_data: BookCreateModel):
    return {"title": book_data.title, "author": book_data.author}
</code></pre>
<h3 id="heading-what-is-serialization">🔍 What is Serialization?</h3>
<p>Serialization is the process of converting a data object (like a model) into a format (e.g., JSON) that can be easily stored or transferred. FastAPI does this under the hood using Pydantic.</p>
<h2 id="heading-reading-request-headers">📬 Reading Request Headers</h2>
<pre><code class="lang-plaintext">from fastapi import Header

@app.get("/get_headers")
async def get_header(
    accept: str = Header(None),
    content_type: str = Header(None),
    user_agent: str = Header(None),
    host: str = Header(None)):

    return {
        "Accept": accept,
        "Content-type": content_type,
        "User Agent": user_agent,
        "Host": host
    }
</code></pre>
<p>Useful for debugging or tailoring responses based on request metadata.</p>
<hr />
<h2 id="heading-crud-api-the-big-picture">📚 CRUD API - The Big Picture</h2>
<p>FastAPI supports complete REST-style APIs. Here’s a breakdown of HTTP methods:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Method</td><td>Purpose</td><td>Example Endpoint</td></tr>
</thead>
<tbody>
<tr>
<td>GET</td><td>Read a resource</td><td><code>/books</code></td></tr>
<tr>
<td>POST</td><td>Create a resource</td><td><code>/books</code></td></tr>
<tr>
<td>PATCH</td><td>Update a resource</td><td><code>/book/{book_id}</code></td></tr>
<tr>
<td>DELETE</td><td>Delete a resource</td><td><code>/book/{book_id}</code></td></tr>
</tbody>
</table>
</div><p>The "resource" here typically refers to data models like <code>Book</code>, <code>User</code>, <code>Article</code>, etc.</p>
<h2 id="heading-key-takeaways">🧠 Key Takeaways</h2>
<ul>
<li><p><strong>FastAPI</strong> is intuitive and async-first.</p>
</li>
<li><p><strong>Pydantic</strong> makes request validation automatic.</p>
</li>
<li><p>Headers, query/path parameters, and CRUD routes are simple to implement.</p>
</li>
<li><p>We can already imagine this backend talking to AI APIs or powering a SaaS app.</p>
</li>
</ul>
<hr />
<h2 id="heading-whats-next">🔭 What's Next</h2>
<ul>
<li><p>🔄 Full CRUD implementation</p>
</li>
<li><p>🧠 Connect to database (PostgreSQL or SQLite)</p>
</li>
<li><p>🤖 Integrate OpenAI APIs</p>
</li>
<li><p>🚀 Deploy a SaaS-style product</p>
</li>
</ul>
<p>If you're also diving into FastAPI, let’s connect and build in public together. Cheers to progress! 💻⚡</p>
<hr />
<p><strong>#FastAPI #Python #BackendDevelopment #WebDev #Pydantic #LearningInPublic #OpenSource #AI #SaaS</strong></p>
]]></content:encoded></item></channel></rss>