<?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: Khalil Habib Shariff</title>
    <description>The latest articles on DEV Community by Khalil Habib Shariff (@khaleelhabeeb).</description>
    <link>https://dev.to/khaleelhabeeb</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%2F976746%2F88d06caf-ab78-4f12-9bef-1480b1070688.JPG</url>
      <title>DEV Community: Khalil Habib Shariff</title>
      <link>https://dev.to/khaleelhabeeb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khaleelhabeeb"/>
    <language>en</language>
    <item>
      <title>Rococo Supercharged Immutability, Time-Travel Debugging &amp; Event-Driven Workflows</title>
      <dc:creator>Khalil Habib Shariff</dc:creator>
      <pubDate>Tue, 18 Nov 2025 18:07:30 +0000</pubDate>
      <link>https://dev.to/khaleelhabeeb/rococo-supercharged-immutability-time-travel-debugging-event-driven-workflows-4jk6</link>
      <guid>https://dev.to/khaleelhabeeb/rococo-supercharged-immutability-time-travel-debugging-event-driven-workflows-4jk6</guid>
      <description>&lt;h2&gt;
  
  
  How Rococo Supercharged My Banking API: Immutability, Time-Travel Debugging &amp;amp; Event-Driven Workflows
&lt;/h2&gt;

&lt;p&gt;When I started building a small banking API for learning purposes, I expected the hardest parts to be the API endpoints or the money transfer logic.&lt;/p&gt;

&lt;p&gt;I was wrong.&lt;/p&gt;

&lt;p&gt;The real challenge was &lt;strong&gt;data correctness over time&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If a customer deposits money, withdraws money, initiates a dispute, or reports that something went wrong earlier in the month, traditional CRUD becomes the enemy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Updates erase history
&lt;/li&gt;
&lt;li&gt;Deletes destroy audit trails
&lt;/li&gt;
&lt;li&gt;Logs can’t rebuild financial state
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In financial systems, &lt;strong&gt;data is not just data — it’s truth&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
This is where &lt;strong&gt;Rococo&lt;/strong&gt;, a Python versioning + event-sourcing framework, completely changed the game for me.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧠 Why CRUD is a trap in banking
&lt;/h2&gt;

&lt;p&gt;Imagine a basic workflow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Start balance: $0
Deposit $100 → balance = $100
Withdraw $20 → balance = $80

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

&lt;/div&gt;



&lt;p&gt;In traditional systems, the &lt;code&gt;balance&lt;/code&gt; column gets overwritten twice.&lt;/p&gt;

&lt;p&gt;So when a customer asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What was my balance before I withdrew $20 on January 12?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can’t answer — because the previous state is gone.&lt;/p&gt;

&lt;p&gt;With Rococo, &lt;strong&gt;every state transition becomes a new immutable version&lt;/strong&gt;, creating a perfect historical timeline instead of destructive updates.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔥 Rococo’s magic: Immutable Version Models
&lt;/h2&gt;

&lt;p&gt;Here’s what my &lt;code&gt;Account&lt;/code&gt; model looks like with Rococo:&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="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;VersionedModel&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;deposit&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;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;actor_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Account&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;replace&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;balance&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="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;changed_by_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;actor_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;changed_on&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;utcnow&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="n"&gt;previous_version&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="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="o"&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;uuid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uuid4&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;Every deposit (or withdrawal) produces a &lt;strong&gt;brand-new version&lt;/strong&gt; of the entity — nothing is overwritten.&lt;/p&gt;

&lt;p&gt;This enables a superpower:&lt;/p&gt;

&lt;h3&gt;
  
  
  Time-travel debugging &amp;amp; dispute resolution
&lt;/h3&gt;

&lt;p&gt;Calling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /accounts/{account_id}/versions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;returns the entire lifetime of an account:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Balance&lt;/th&gt;
&lt;th&gt;Actor&lt;/th&gt;
&lt;th&gt;Timestamp&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;v1&lt;/td&gt;
&lt;td&gt;$0&lt;/td&gt;
&lt;td&gt;system&lt;/td&gt;
&lt;td&gt;2024-01-01&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;v2&lt;/td&gt;
&lt;td&gt;$100&lt;/td&gt;
&lt;td&gt;user-123&lt;/td&gt;
&lt;td&gt;2024-01-02&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;v3&lt;/td&gt;
&lt;td&gt;$80&lt;/td&gt;
&lt;td&gt;user-123&lt;/td&gt;
&lt;td&gt;2024-01-03&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Now when a user claims:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“My balance is wrong”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I don’t guess.&lt;br&gt;
I &lt;strong&gt;show the exact historical truth&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔒 Built-in audit trail — without writing custom audit code
&lt;/h2&gt;

&lt;p&gt;Rococo automatically records:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;previous version&lt;/li&gt;
&lt;li&gt;new version&lt;/li&gt;
&lt;li&gt;who made the change&lt;/li&gt;
&lt;li&gt;when it happened&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s the kind of audit schema it creates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;id | entity_id | version | previous_version | balance | currency |
created_by_id | created_on | active
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I didn’t write any audit logic at all — Rococo handled everything.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚡ Event-driven architecture with zero friction
&lt;/h2&gt;

&lt;p&gt;The next killer feature: &lt;strong&gt;auto-publishing events&lt;/strong&gt; when an entity changes.&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;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;repo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BaseRepository&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;adapter&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="n"&gt;adapter&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;Account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;message_adapter&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="n"&gt;message_adapter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;queue_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;account_events&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;Now every account update generates a message on the event bus (RabbitMQ, SQS, etc.)&lt;/p&gt;

&lt;p&gt;This allowed my system to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;trigger fraud detection workflows&lt;/li&gt;
&lt;li&gt;sync account balances to analytics&lt;/li&gt;
&lt;li&gt;push updates to the frontend in real-time&lt;/li&gt;
&lt;li&gt;track money movement in parallel systems without polling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Event-driven UX with almost no extra code.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧩 System Architecture of the Project
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FastAPI  ⟶  Service Layer  ⟶  Rococo Repository  ⟶ PostgreSQL
                                             ⟶ Audit Table
                                             ⟶ Event Bus
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Frontend stack: &lt;strong&gt;Vue 3&lt;/strong&gt;&lt;br&gt;
Backend stack: &lt;strong&gt;FastAPI + Rococo&lt;/strong&gt;&lt;br&gt;
Database: &lt;strong&gt;PostgreSQL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;🔗 GitHub Repository: &lt;em&gt;&lt;a href="https://github.com/Khaleelhabeeb/banking_ledger" rel="noopener noreferrer"&gt;https://github.com/Khaleelhabeeb/banking_ledger&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
🔗 Live Demo: &lt;em&gt;&lt;a href="https://bankingledger.vercel.app" rel="noopener noreferrer"&gt;https://bankingledger.vercel.app&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🏁 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Rococo didn’t just make my banking API &lt;em&gt;work&lt;/em&gt; —&lt;br&gt;
it made it &lt;strong&gt;correct, traceable, and auditable&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Without extra effort, I gained:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Zero-loss history of data&lt;/li&gt;
&lt;li&gt;Permanent audit trail&lt;/li&gt;
&lt;li&gt;Time-travel debugging&lt;/li&gt;
&lt;li&gt;Event sourcing with minimal complexity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re working in a domain where &lt;strong&gt;truth and history matter more than speed&lt;/strong&gt;, Rococo deserves a spot in your toolbox.&lt;/p&gt;




&lt;h2&gt;
  
  
  💬 Want to chat?
&lt;/h2&gt;

&lt;p&gt;I’m actively experimenting with Rococo and plan to build more adapters (DynamoDB next 👀).&lt;/p&gt;

&lt;p&gt;If you’re working with Rococo, event-driven architectures, or just enjoy these concepts — I’d love to connect.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🙌&lt;/p&gt;

</description>
      <category>api</category>
      <category>backend</category>
      <category>python</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Understanding python Decorators</title>
      <dc:creator>Khalil Habib Shariff</dc:creator>
      <pubDate>Mon, 04 Mar 2024 19:43:51 +0000</pubDate>
      <link>https://dev.to/khaleelhabeeb/understanding-python-decorators-4el4</link>
      <guid>https://dev.to/khaleelhabeeb/understanding-python-decorators-4el4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Understand Python Decorators: A Twist on Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Have you ever encountered the @ symbol used with functions in Python and wondered what it meant? That's the magic of decorators, a unique concept that adds functionality to existing functions without altering their original code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, what are decorators?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine wrapping a present. The present itself (the function) remains unchanged, but the wrapping (the decorator) adds something extra – maybe a bow or a ribbon. Similarly, a decorator "wraps" a function, adding new features or modifying its behavior.&lt;br&gt;
&lt;strong&gt;Let's see an example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import time

def timer(func):
    #Decorator that logs the execution time of a function.

    def wrapper(*args, **kwargs):
        start_time = time.time()
        result = func(*args, **kwargs)
        end_time = time.time()
        print(f"{func.__name__} took {end_time - start_time:.2f} seconds to execute.")
        return result

    return wrapper

@timer
def my_function(a, b):
    #This function does some calculations.
    return a * b + 5

result = my_function(3, 4)
print(result) # Output: my_function took 0.00 seconds to execute.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the timer decorator is a function that takes another function (func) as its argument. It then defines an inner function (wrapper) that executes the original function (func) and logs its execution time. Finally, the decorator returns the wrapper function, which replaces the original one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of using decorators:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Code Reusability:&lt;/strong&gt; You can create reusable decorators for common tasks like logging, authentication, or caching, avoiding repetitive code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Maintainability:&lt;/strong&gt; Code becomes cleaner and easier to understand by separating concerns (core functionality and additional features).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flexibility:&lt;/strong&gt; You can easily add or remove functionalities using decorators without modifying the original function code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decorators are versatile and can be used for various purposes:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Such AS:&lt;/strong&gt;&lt;br&gt;
-Logging, Authentication, Caching, Validation &lt;/p&gt;

&lt;p&gt;Remember, decorators add a unique twist to functions in Python, making them a powerful tool for writing clean, maintainable, and feature-rich code. So, embrace the fun and start decorating your functions today.&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Building A Simple API For Your ML Model With FastAPI</title>
      <dc:creator>Khalil Habib Shariff</dc:creator>
      <pubDate>Sat, 23 Dec 2023 12:17:07 +0000</pubDate>
      <link>https://dev.to/khaleelhabeeb/building-a-simple-api-for-your-ml-model-with-fastapi-3gi2</link>
      <guid>https://dev.to/khaleelhabeeb/building-a-simple-api-for-your-ml-model-with-fastapi-3gi2</guid>
      <description>&lt;p&gt;Machine learning models are powerful tools, but their impact is often confined to notebooks and research environments. To realize their full potential, we need to integrate them into real-world applications. FastAPI offers a streamlined and efficient way to create APIs that bridge this gap, making your models accessible to diverse use cases.&lt;br&gt;
In this post, I will guide you through the process of building a simple API for a plant disease classification model using FastAPI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;KEY STEPS&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install FastAPI and Dependencies:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install fastapi uvicorn[standard] tensorflow numpy pillow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;2.Create Your FastAPI App:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from fastapi import FastAPI, File, UploadFile, BackgroundTasks
# ... other imports

app = FastAPI()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.Load Your Trained Model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model = keras.models.load_model('./models/model.weights.best.hdf5')

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

&lt;/div&gt;



&lt;p&gt;4.Define Prediction Function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async def predict_leaf_class(image: UploadFile):
    # ... image preprocessing and prediction logic
    return predicted_class

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

&lt;/div&gt;



&lt;p&gt;5.Create API Endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.post("/predict")
async def predict_leaf_disease(image: UploadFile = File(...)):
    predicted_class = await predict_leaf_class(image)
    return JSONResponse(content={"predicted_class": predicted_class})

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

&lt;/div&gt;



&lt;p&gt;6.Enable CORS (Optional):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # Adjust for production
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

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

&lt;/div&gt;



&lt;p&gt;7.Run The API&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;uvicorn main:app --reload

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

&lt;/div&gt;



&lt;p&gt;You can find the complete code in this repo [&lt;a href="https://github.com/Khaleelhabeeb/Fastapi-ML-Model-API"&gt;https://github.com/Khaleelhabeeb/Fastapi-ML-Model-API&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
FastAPI simplifies the process of creating robust and scalable APIs for machine learning models. By following these steps, you can effectively share your models with other applications and users, enabling a wider range of practical applications.&lt;br&gt;
visit [&lt;a href="https://github.com/Khaleelhabeeb/Fastapi-ML-Model-API"&gt;https://github.com/Khaleelhabeeb/Fastapi-ML-Model-API&lt;/a&gt;]&lt;/p&gt;

</description>
      <category>api</category>
      <category>beginners</category>
      <category>python</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What's New In Flask 3.0</title>
      <dc:creator>Khalil Habib Shariff</dc:creator>
      <pubDate>Mon, 30 Oct 2023 19:18:43 +0000</pubDate>
      <link>https://dev.to/khaleelhabeeb/whats-new-in-flask-30-2g5a</link>
      <guid>https://dev.to/khaleelhabeeb/whats-new-in-flask-30-2g5a</guid>
      <description>&lt;p&gt;Flask 3.0: Now with more features and customization!&lt;/p&gt;

&lt;p&gt;Flask is a popular Python web framework that is known for its simplicity and flexibility. Flask 3.0 is a major release that includes a number of new features and improvements.&lt;/p&gt;

&lt;p&gt;Here is a summary of the most important new features in Flask 3.0:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;New customization points for many previously global behaviors&lt;/strong&gt;. This makes it easier to tailor Flask to your specific needs. For example, you can now customize the way that Flask handles errors, redirects, and JSON serialization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Added the View.init_every_request class attribute&lt;/strong&gt;. If a view subclass sets this to False, the view will not create a new instance on every request. This can be useful for performance-critical views.
-** Teardown functions are always run at the end of the request, even if the context is preserved**. They are also run after the preserved context is popped. This ensures that cleanup code is always executed, even if an exception is raised.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The CLI does not pass script_info to app factory functions&lt;/strong&gt;. This avoids a potential conflict between the script_info and the URL_PREFIX configuration option.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;config.from_json is replaced by config.from_file(name, load=json.load)&lt;/strong&gt;. The new API is more flexible and allows you to use other JSON libraries besides the standard library's json module.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;json functions no longer take an encoding parameter&lt;/strong&gt;. JSON encoding is now handled internally by Flask, so you no longer need to specify the encoding explicitly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;safe_join is removed. Use werkzeug.utils.safe_join instead&lt;/strong&gt;. This ensures that the safe_join function is always available, even if you are not using Flask's default dependency injection container.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;total_seconds is removed. Use timedelta.total_seconds instead&lt;/strong&gt;. This change reflects the fact that timedelta is the preferred way to represent time intervals in Python.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The same blueprint cannot be registered with the same name&lt;/strong&gt;. Use name= when registering to specify a unique name. This prevents conflicts between blueprints with the same name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition to these new features, Flask 3.0 also includes a number of bug fixes and performance improvements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are some examples of how to use the new features in Flask 3.0&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Customizing global behaviors&lt;/strong&gt;&lt;br&gt;
To customize a global behavior, you can now use the app.customizer dictionary. This dictionary maps behavior names to functions that can be used to customize the behavior.&lt;/p&gt;

&lt;p&gt;For example, to customize the way that Flask handles errors, you could use the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, render_template

app = Flask(__name__)

app.customizer["errorhandler"][404] = lambda e: render_template("404.html")

if __name__ == "__main__":
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code tells Flask to use the 404.html template to render a 404 error page.&lt;/p&gt;

&lt;p&gt;To use the View.init_every_request class attribute, you can simply set it to False in your view subclass. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, render_template

app = Flask(__name__)

class MyView(flask.View):
    init_every_request = False

    def dispatch_request(self):
        return render_template("my_view.html")

app.add_url_rule("/my_view", view_func=MyView.as_view("my_view"))

if __name__ == "__main__":
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code tells Flask to only create a new instance of the MyView class on the first request. On subsequent requests, Flask will reuse the existing instance.&lt;/p&gt;

&lt;p&gt;Overall, Flask 3.0 is a significant release with a number of new features and improvements. If you are using Flask, I encourage you to upgrade to version 3.0 as soon as possible.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>python</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How To Connect Flask App To Any Database</title>
      <dc:creator>Khalil Habib Shariff</dc:creator>
      <pubDate>Mon, 23 Oct 2023 20:53:15 +0000</pubDate>
      <link>https://dev.to/khaleelhabeeb/how-to-connect-flask-app-to-any-database-o5i</link>
      <guid>https://dev.to/khaleelhabeeb/how-to-connect-flask-app-to-any-database-o5i</guid>
      <description>&lt;p&gt;Connecting Flask to MySQL, PostgreSQL, MongoDB, and Firebase&lt;/p&gt;

&lt;p&gt;Flask is a lightweight and flexible web framework for Python. It is a popular choice for developing web applications of all sizes.&lt;/p&gt;

&lt;p&gt;Flask does not come with a built-in database abstraction layer (DAL). This means that developers need to choose and install a third-party DAL such as SQLAlchemy or Peewee.&lt;/p&gt;

&lt;p&gt;Here are some tips on how to connect Flask to MySQL, PostgreSQL, MongoDB, and Firebase:&lt;/p&gt;

&lt;p&gt;Connecting Flask to MySQL&lt;/p&gt;

&lt;p&gt;To connect Flask to MySQL, you will need to install the MySQLdb library. Once you have installed MySQLdb, you can import it into your Flask application and create a connection to the MySQL database.&lt;/p&gt;

&lt;p&gt;Here is an example of how to connect Flask to MySQL:&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 Flask-MySQLdb
pip install PyMySQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask
import MySQLdb

app = Flask(__name__)

# Create a connection to the MySQL database
db = MySQLdb.connect(
    host='localhost',
    user='root',
    password='password',
    database='my_database',
)

# Create a cursor object
cursor = db.cursor()

# Execute a SQL query
cursor.execute('SELECT * FROM users')

# Get the results of the query
results = cursor.fetchall()

# Close the cursor and the connection
cursor.close()
db.close()

if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connecting Flask to PostgreSQL&lt;/p&gt;

&lt;p&gt;To connect Flask to PostgreSQL, you will need to install the psycopg2 library. Once you have installed psycopg2, you can import it into your Flask application and create a connection to the PostgreSQL database.&lt;/p&gt;

&lt;p&gt;Here is an example of how to connect Flask to PostgreSQL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask
import psycopg2

app = Flask(__name__)

# Create a connection to the PostgreSQL database
conn = psycopg2.connect(
    host='localhost',
    user='postgres',
    password='password',
    database='my_database',
)

# Create a cursor object
cursor = conn.cursor()

# Execute a SQL query
cursor.execute('SELECT * FROM users')

# Get the results of the query
results = cursor.fetchall()

# Close the cursor and the connection
cursor.close()
conn.close()

if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connecting Flask to MongoDB&lt;/p&gt;

&lt;p&gt;To connect Flask to MongoDB, you will need to install the pymongo library. Once you have installed pymongo, you can import it into your Flask application and create a connection to the MongoDB database.&lt;/p&gt;

&lt;p&gt;Here is an example of how to connect Flask to MongoDB:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask
import pymongo

app = Flask(__name__)

# Create a connection to the MongoDB database
client = pymongo.MongoClient('localhost', 27017)
db = client['my_database']

# Get the users collection
users_collection = db['users']

# Find all users
users = users_collection.find()

# Close the connection
client.close()

if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connecting Flask to Firebase&lt;/p&gt;

&lt;p&gt;To connect Flask to Firebase, you will need to install the Pyrebase library. Once you have installed Pyrebase, you can import it into your Flask application and initialize the Firebase Realtime Database.&lt;/p&gt;

&lt;p&gt;Here is an example of how to connect Flask to Firebase:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask
import pyrebase

app = Flask(__name__)

# Initialize the Firebase Realtime Database
config = {
    'apiKey': 'YOUR_API_KEY',
    'authDomain': 'YOUR_AUTH_DOMAIN',
    'databaseURL': 'YOUR_DATABASE_URL',
    'projectId': 'YOUR_PROJECT_ID',
    'storageBucket': 'YOUR_STORAGE_BUCKET',
    'messagingSenderId': 'YOUR_MESSAGING_SENDER_ID'
}

firebase = pyrebase.initialize_app(config)

# Get the users reference
users_ref = firebase.database().reference('users')

# Get all users
users = users_ref.get()

if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are just a few examples of how to connect Flask to MySQL, PostgreSQL, MongoDB, and Firebase. There are many other ways to do this, and the best approach for you will depend on your specific needs.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>python</category>
      <category>database</category>
    </item>
    <item>
      <title>A Beginner's Guide To Creating a Simple RESTful API with Python Flask</title>
      <dc:creator>Khalil Habib Shariff</dc:creator>
      <pubDate>Fri, 28 Jul 2023 13:56:14 +0000</pubDate>
      <link>https://dev.to/khaleelhabeeb/creating-a-simple-restful-api-with-python-flask-2643</link>
      <guid>https://dev.to/khaleelhabeeb/creating-a-simple-restful-api-with-python-flask-2643</guid>
      <description>&lt;p&gt;Step 1: Setup&lt;br&gt;
First, make sure you have Python installed on your system. You can download Python from the official website:(&lt;a href="https://www.python.org/downloads/"&gt;https://www.python.org/downloads/&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Next, install Flask using pip, the Python package manager. Open a terminal or command prompt and 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;pip install Flask
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Create the Flask App&lt;br&gt;
Create a new Python file (e.g., app.py) and import the necessary modules:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, jsonify, request
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, initialize the Flask app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app = Flask(__name__)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3: Define Routes and Endpoints&lt;br&gt;
In Flask, you define routes using the @app.route decorator. Each route corresponds to a specific URL, and each URL will be associated with a function that handles the request and returns the response.&lt;/p&gt;

&lt;p&gt;Let's create a simple API with two endpoints: one to get a list of items and another to get details of a specific item.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Sample data - you can replace this with your own data or use a database
items = [
    {"id": 1, "name": "Item 1"},
    {"id": 2, "name": "Item 2"},
    {"id": 3, "name": "Item 3"}
]

# Endpoint to get all items
@app.route('/api/items', methods=['GET'])
def get_items():
    return jsonify(items)

# Endpoint to get details of a specific item
@app.route('/api/items/&amp;lt;int:item_id&amp;gt;', methods=['GET'])
def get_item(item_id):
    item = next((item for item in items if item['id'] == item_id), None)
    if item:
        return jsonify(item)
    return jsonify({"message": "Item not found"}), 404

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

&lt;/div&gt;



&lt;p&gt;Step 4: Run the Flask App&lt;br&gt;
At the end of your app.py file, add the following lines to run the app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 5: Test the API&lt;br&gt;
Save the file and run it using the following command in the terminal:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Your Flask app should now be running locally at &lt;a href="http://127.0.0.1:5000/"&gt;http://127.0.0.1:5000/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To test the API, you can use tools like curl, Postman, or simply use your web browser.&lt;/p&gt;

&lt;p&gt;To get all items, open your web browser and go to &lt;a href="http://127.0.0.1:5000/api/items"&gt;http://127.0.0.1:5000/api/items&lt;/a&gt;.&lt;br&gt;
To get details of a specific item (e.g., item with ID 2), go to &lt;a href="http://127.0.0.1:5000/api/items/2"&gt;http://127.0.0.1:5000/api/items/2&lt;/a&gt;.&lt;br&gt;
Congratulations! You have just created a simple RESTful API with Python and Flask. From here, you can continue exploring more advanced features of Flask, like handling POST, PUT, and DELETE requests, using a database, authentication, etc. Happy coding!.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building a Simple API with Node.js and Express</title>
      <dc:creator>Khalil Habib Shariff</dc:creator>
      <pubDate>Sat, 29 Apr 2023 14:00:33 +0000</pubDate>
      <link>https://dev.to/khaleelhabeeb/building-a-simple-api-with-nodejs-and-express-d6c</link>
      <guid>https://dev.to/khaleelhabeeb/building-a-simple-api-with-nodejs-and-express-d6c</guid>
      <description>&lt;p&gt;1.Setting Up the Project:&lt;br&gt;
To get started, create a new directory for your project and navigate into it using the terminal. Then, initialize a new Node.js project by running 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;npm init -y

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

&lt;/div&gt;



&lt;p&gt;This will create a package.json file in your project directory, which is used to manage your project's dependencies and scripts.&lt;/p&gt;

&lt;p&gt;Next, install the express package by running 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;npm install express

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

&lt;/div&gt;



&lt;p&gt;This will install express and its dependencies in your project.&lt;/p&gt;

&lt;p&gt;2.Creating a Simple Server:&lt;br&gt;
Create a new file called server.js in your project directory, and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const app = express();

app.listen(3000, () =&amp;gt; {
  console.log('Server is listening on port 3000');
});

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

&lt;/div&gt;



&lt;p&gt;This code imports the express package and creates a new instance of the express application. We then call the app.listen() method to start the server and listen for incoming requests on port 3000.&lt;/p&gt;

&lt;p&gt;3.Creating Routes:&lt;br&gt;
To create a route, we need to define an HTTP method and a URL path, and associate it with a callback function that will handle the request. In express, we can use the app.get(), app.post(), app.put(), and app.delete() methods to define routes for different HTTP methods.&lt;br&gt;
For example, let's create a route that responds to GET requests to the root URL ('/'):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/', (req, res) =&amp;gt; {
  res.send('Hello, world!');
});

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

&lt;/div&gt;



&lt;p&gt;This code defines a route for GET requests to the root URL ('/'), and sends a response with the text 'Hello, world!'.&lt;/p&gt;

&lt;p&gt;4.Parsing Request Bodies:&lt;br&gt;
To parse request bodies, we can use the body-parser package. First, install the package by running 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;npm install body-parser

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

&lt;/div&gt;



&lt;p&gt;Then, import it in your server.js file and use it as middleware:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bodyParser = require('body-parser');

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

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

&lt;/div&gt;



&lt;p&gt;This code tells express to use the body-parser middleware to parse request bodies encoded in URL-encoded form or JSON format.&lt;/p&gt;

&lt;p&gt;5.Creating Routes that Handle Data:&lt;br&gt;
Let's create another route that responds to POST requests to the /items URL, and expects a JSON-encoded request body with an id and a name property. We'll store the items in an array for now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let items = [];

app.post('/items', (req, res) =&amp;gt; {
  const { id, name } = req.body;
  items.push({ id, name });
  res.status(201).json({ message: 'Item created', item: { id, name } });
});

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

&lt;/div&gt;



&lt;p&gt;This code defines a route for POST requests to the /items URL, and uses destructuring to extract the id and name properties from the request body. We then push the new item to the items array and send a response with a JSON-encoded message and the new item.&lt;/p&gt;

&lt;p&gt;6.Testing the API:&lt;br&gt;
To test your API, start the server by running the following command in your project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node server.js

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

&lt;/div&gt;



&lt;p&gt;Then, use a tool like curl or Postman to send requests to your API and verify that it works as expected.&lt;/p&gt;

&lt;p&gt;Congratulations, you've created a simple API with Node.js! Of course, this is just the beginning - there's a lot more to learn about Node.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A Beginner's Guide to Creating a RESTful API with Node.js</title>
      <dc:creator>Khalil Habib Shariff</dc:creator>
      <pubDate>Sun, 26 Mar 2023 00:22:33 +0000</pubDate>
      <link>https://dev.to/khaleelhabeeb/a-beginners-guide-to-creating-a-restful-api-with-nodejs-2k27</link>
      <guid>https://dev.to/khaleelhabeeb/a-beginners-guide-to-creating-a-restful-api-with-nodejs-2k27</guid>
      <description>&lt;p&gt;Creating a simple API using Node.js is a common use case for the platform, and there are several libraries and frameworks available to make the process easier. Here's a brief overview of how to create a simple API using Node.js.&lt;/p&gt;

&lt;p&gt;1.Choose a framework: There are several popular Node.js frameworks for building APIs, such as Express, Hapi, and Koa. For this example, we'll use Express.&lt;/p&gt;

&lt;p&gt;2.Install dependencies: Once you've chosen a framework, you'll need to install the necessary dependencies. For Express, you'll need to install the express and body-parser packages. You can do this using the npm package manager:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express body-parser
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a basic server: Create a new file called server.js, and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const bodyParser = require('body-parser');

const app = express();

app.use(bodyParser.json());

app.get('/', (req, res) =&amp;gt; {
  res.send('Hello, world!');
});

const port = process.env.PORT || 3000;

app.listen(port, () =&amp;gt; {
  console.log(`Server running on port ${port}`);
});

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

&lt;/div&gt;



&lt;p&gt;This creates a basic Express server that listens for HTTP requests on port 3000 (or the value of the PORT environment variable, if set). When a GET request is made to the root URL ('/'), the server responds with the string 'Hello, world!'.&lt;/p&gt;

&lt;p&gt;4.Add API routes: To create an API, you'll need to define routes that handle different HTTP methods (such as GET, POST, PUT, and DELETE) and perform actions based on the request parameters. For example, to create a route that returns a list of items, you could add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const items = ['apple', 'banana', 'orange'];

app.get('/items', (req, res) =&amp;gt; {
  res.json(items);
});

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

&lt;/div&gt;



&lt;p&gt;This defines a new route that listens for GET requests to the '/items' URL. When a request is received, the server responds with a JSON array containing the items array defined earlier.&lt;/p&gt;

&lt;p&gt;5.Test the API: You can test the API using a tool like Postman or cURL. For example, to test the '/items' route, you can send a GET request to &lt;a href="http://localhost:3000/items"&gt;http://localhost:3000/items&lt;/a&gt;. The server should respond with a JSON array containing the items.&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>javascript</category>
      <category>api</category>
    </item>
  </channel>
</rss>
