<?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: Jack Henza</title>
    <description>The latest articles on DEV Community by Jack Henza (@jackh404).</description>
    <link>https://dev.to/jackh404</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%2F1190195%2F1cfd485b-658d-49cf-9570-a1cda5a80e70.jpeg</url>
      <title>DEV Community: Jack Henza</title>
      <link>https://dev.to/jackh404</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jackh404"/>
    <language>en</language>
    <item>
      <title>Diving into TypeScript and Tailwind</title>
      <dc:creator>Jack Henza</dc:creator>
      <pubDate>Wed, 17 Jan 2024 21:55:29 +0000</pubDate>
      <link>https://dev.to/jackh404/diving-into-typescript-and-tailwind-2fpe</link>
      <guid>https://dev.to/jackh404/diving-into-typescript-and-tailwind-2fpe</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In the dynamic world of full-stack development, I recently embarked on an exciting project involving a React frontend and Flask backend. This journey was not just about building a web application, but also about embracing and mastering new technologies on the fly: TypeScript and Tailwind CSS. In this blog post, I want to share my experiences, challenges, and learnings from integrating these powerful tools into my development workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Project Setting
&lt;/h2&gt;

&lt;p&gt;The project was a web application with React's dynamic UI capabilities paired with Flask's straightforward and efficient backend. The challenge? I decided to integrate TypeScript for stronger type safety and Tailwind CSS for a more efficient styling process, both of which were (relatively) new to me.&lt;/p&gt;

&lt;h3&gt;
  
  
  Integrating TypeScript
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Why TypeScript?&lt;/strong&gt; TypeScript, as a statically typed superset of JavaScript, appealed to me for its ability to catch errors early in the development process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Learning Process:&lt;/strong&gt; Initially, TypeScript's strict typing seemed like a constraint compared to JavaScript's flexibility. I faced a steep learning curve understanding its interfaces and types, especially when applying them to existing React components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Overcoming TypeScript Hurdles:&lt;/strong&gt; I tackled this by starting with simple components and gradually scaling up. I heavily relied on TypeScript documentation, community forums, and trial and error. The real value of TypeScript becomes evident when it prevents you from deploying code that looks fine but causes runtime errors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Embracing Tailwind CSS
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Choosing Tailwind CSS:&lt;/strong&gt; I was intrigued by Tailwind CSS's utility-first approach, which promised a faster and more manageable styling process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Transition:&lt;/strong&gt; Shifting from traditional CSS to thinking in terms of utility classes in Tailwind was initially challenging. It required a different mindset and approach to styling I found myself starting to create an id or a class that would only be used a few times before remembering (with no small amount of joy) that I could simply slap a few utilities right in the tsx.&lt;/p&gt;

&lt;h2&gt;
  
  
  Merging TypeScript with React and Flask
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Handling API Responses:&lt;/strong&gt; One of the more intricate tasks was ensuring TypeScript accurately reflected the data structures exchanged between React and Flask. I defined TypeScript interfaces to mirror Flask's response objects, enhancing type safety across the full stack. This made it easy to spot potential issues with how components might misbehave before requests are returned.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;State Management in React:&lt;/strong&gt; TypeScript brought clarity and predictability to state and props management in React. It proved invaluable in managing complex components and state logic, significantly reducing potential runtime errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Begin with Small Steps:&lt;/strong&gt; Start with simple integrations and gradually expand your use of new technologies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dive into Documentation:&lt;/strong&gt; The comprehensive documentation for TypeScript and Tailwind CSS is a goldmine of information. Use it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leverage the Community:&lt;/strong&gt; The developer community is rich with practical examples and advice that proved invaluable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Learn Iteratively:&lt;/strong&gt; Adopting TypeScript and Tailwind is a continuous learning process, best approached with patience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Apply What You Learn:&lt;/strong&gt; Practical application cements theoretical knowledge. Using these technologies in real scenarios was crucial for my understanding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't be pridefull:&lt;/strong&gt; Sometimes you just have to ask somebody. Bonus points if they're a real person.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Integrating TypeScript and Tailwind CSS into my React/Flask project initially seemed intimidating, but it turned out to be an enriching and edifying experience. This journey underscores the fact that the key to success in the tech world is a willingness to continuously learn and adapt. I hope others will be inspired to embrace new technologies and explore the endless possibilities in the realm of full-stack development.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>First Fullstack App</title>
      <dc:creator>Jack Henza</dc:creator>
      <pubDate>Fri, 22 Dec 2023 13:15:18 +0000</pubDate>
      <link>https://dev.to/jackh404/first-fullstack-app-510m</link>
      <guid>https://dev.to/jackh404/first-fullstack-app-510m</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Embarking on the journey of building a full stack web application has been both challenging and rewarding. In this blog post, we'll explore the process of creating a modern full stack app using Flask, SQLAlchemy, React, and Vite. Each of these technologies plays a crucial role in different layers of the application, combining to deliver a seamless and performant user experience. Other technologies could easily be incorporated, such as tailwind css, flowbite, or bootstrap. Various hosting services can be used, like render, netlify, or even supabase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;We'll be separating our codebase into two main divisions: server and client. Go ahead and create your server directory now, but don't cd into it in your terminal yet. Your python virtual environment should be set up in the root directory. We'll create the client directory later when we scaffold our React app using Vite.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up the Backend with Flask and SQLAlchemy
&lt;/h3&gt;

&lt;p&gt;Flask, a micro web framework for Python, provides a solid foundation for our backend. To persist and manage data, we'll use SQLAlchemy, a powerful SQL toolkit and Object-Relational Mapping (ORM) library.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install Flask and SQLAlchemy:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;pipenv &lt;span class="nb"&gt;install&lt;/span&gt;
...
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;pipenv shell
...
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;server
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;Flask SQLAlchemy
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create a Flask App:&lt;/strong&gt;&lt;br&gt;
Create an app.py file in your server folder. This will hold your backend logic, communicating with your database and serving data to your front end.&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="c1"&gt;# app.py
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;render_template&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;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&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;index&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;render_template&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;index.html&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&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;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;debug&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Initialize SQLAlchemy:&lt;/strong&gt;&lt;br&gt;
Create a file called models.py. This will hold the code that builds your 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="c1"&gt;# models.py
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask_sqlalchemy&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;SQLAlchemy&lt;/span&gt;

&lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SQLAlchemy&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;Post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Integer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;primary_key&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="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;String&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="n"&gt;nullable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nullable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Frontend Setup with React and Vite
&lt;/h3&gt;

&lt;p&gt;Vite is a next-generation frontend build tool that we'll use to set up our React application.&lt;/p&gt;

&lt;p&gt;Create a Vite App:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ..
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;npm create vite client &lt;span class="nt"&gt;--template&lt;/span&gt; react
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install Dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Connecting the Frontend and Backend
&lt;/h2&gt;

&lt;p&gt;Now that we have our backend and frontend set up, let's connect them to ensure smooth communication between the two.&lt;/p&gt;

&lt;p&gt;CORS Handling in Flask:&lt;br&gt;
Cross Origin Resource Scripting, or CORS, prevents unauthorized access to your back end and database. You'll need to configure it to allow your front end to access your back end.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install the flask-cors extension to handle Cross-Origin Resource Sharing (CORS):&lt;/strong&gt;&lt;br&gt;
Make sure you're in the root directory and run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;Flask-CORS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update app.py to include CORS:&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="c1"&gt;#app.py
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask_cors&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;CORS&lt;/span&gt;
&lt;span class="nc"&gt;CORS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Fetching Data in React:
&lt;/h3&gt;

&lt;p&gt;Fetching data from the front end is relatively straightforward, but can be made simpler with libraries like axios. Personally, I don't mind vanilla React fetches, so let's look at one of those.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;//app.jsx&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&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;App&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&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;setData&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&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;fetchData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &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;try&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/*url*/&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;theData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;theData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&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="nx"&gt;e&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;h2&gt;
  
  
  Database Integration with Flask and SQLAlchemy
&lt;/h2&gt;

&lt;p&gt;Now, let's integrate the SQLAlchemy models with Flask to perform CRUD operations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a Database and Migrate:&lt;/strong&gt;&lt;br&gt;
'Migration' is the term given to creating and changing a database's schema, that is its table and column setup.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;flask db init
flask db migrate &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Initial migration"&lt;/span&gt;
flask db upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Define API Endpoints in Flask:
&lt;/h3&gt;

&lt;p&gt;This code will define endpoints in vanilla flask/SQLAlchemy, though the process can be made more pythonic with another plugin called flask-restfull.&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="c1"&gt;# app.py
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;jsonify&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&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/posts&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;methods&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;GET&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;get_posts&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;query&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="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;jsonify&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;serialize&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&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/posts&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;methods&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;POST&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;create_post&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&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;json&lt;/span&gt;
    &lt;span class="n"&gt;new_post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;title&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&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;new_post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commit&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;jsonify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;serialize&lt;/span&gt;&lt;span class="p"&gt;()),&lt;/span&gt; &lt;span class="mi"&gt;201&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Building a full stack app involves seamlessly integrating multiple technologies. Flask, SQLAlchemy, React, and Vite come together to create a robust and efficient application. As you continue to develop, explore additional features such as authentication, state management, and deployment, you will find that you have your own takes and preferences on this process, as the one outlined here is very barebones.&lt;/p&gt;

&lt;p&gt;Now that you have a foundational understanding, feel free to dive deeper into each technology to unlock their full potential. Happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Learning Back-End Basics</title>
      <dc:creator>Jack Henza</dc:creator>
      <pubDate>Fri, 01 Dec 2023 16:06:33 +0000</pubDate>
      <link>https://dev.to/jackh404/learning-back-end-basics-4la8</link>
      <guid>https://dev.to/jackh404/learning-back-end-basics-4la8</guid>
      <description>&lt;p&gt;For phase 3 of Flatiron School's Software Engineering Program, the final project is a handmade ORM operable by a CLI built with Python and SQLite. Bringing these tools together creates an excellent opportunity to practice object oriented programming, interfacing between multiple languages, and manipulating data at a low level. This was a valuable exercise, as it allowed us to use python to control the full life cycle of a SQL database, from creating tables through adding and updating data to deleting data and dropping tables.&lt;br&gt;
Even more fun, it allowed us to determine our own model for handling many-to-many relationships and join tables. For our project, we elected to use one class to control a primary table and two join tables between it and two other primary tables. This allowed us to use the class as a single source of truth for all the relationships between the three tables, though it created some challenges to overcome around controlling the contents of the join tables and creating instances of the class based on all three associated tables. Overall I think it allowed us to create a more intuitive, pythonic method of controlling the data.&lt;br&gt;
I would recommend this excercise to anyone studying Python, SQL, and/or Object Oriented Programming in general. In the process of building our project, we learned a lot about how all the concepts interact, and were prompted to research and learn new techniques related to all of them.&lt;/p&gt;

</description>
      <category>pyth</category>
      <category>sql</category>
      <category>orm</category>
      <category>cli</category>
    </item>
    <item>
      <title>ObjectObject</title>
      <dc:creator>Jack Henza</dc:creator>
      <pubDate>Mon, 13 Nov 2023 01:29:22 +0000</pubDate>
      <link>https://dev.to/jackh404/objectobject-2638</link>
      <guid>https://dev.to/jackh404/objectobject-2638</guid>
      <description>&lt;p&gt;As a student of the Flatiron School's software engineering program, I have been enjoying the opportunity to learn the React framework. It feels worth noting however that the lack of emphasis on Object Orientation before starting React left many of my classmates without the full picture of what makes React such a brilliant tool. Vanilla JavaScript was not developed with Object Oriented Programming (OOP) in mind, and it appears in the language only as an optional construct for better organizing data. You know, if you really want to. Unfortunately, it is taught the same way at Flatiron, which is to say as an optional module that is easily skipped. I know I am not typing anything revolutionary when I say that OOP is a thing of brilliance and beauty, but I think perhaps seasoned devs take it for granted, not always realizing the paradigm shift it requires of new students of code. It offers an opportunity to get learners thinking in a brand new way. Instead of viewing lines of code as sequential instructions, they can see it nonlinearly, with discreet entities being created that carry out their specific tasks.&lt;br&gt;
React's Java-like structure has the potential to help new coders understand the general lines of reasoning behind more formal languages and larger projects where organization is key, all while they get to feel like they are breezing through creating nifty user interfaces that once would have been much more ponderous to write. I believe, however, that OOP is the bridge between the two, and that being able to see its paradigm even in JavaScript is an invaluable tool for grasping programming's finest forms of problem-solving.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>flatiron</category>
    </item>
    <item>
      <title>A Never Ending Beginning</title>
      <dc:creator>Jack Henza</dc:creator>
      <pubDate>Fri, 20 Oct 2023 22:10:32 +0000</pubDate>
      <link>https://dev.to/jackh404/a-never-ending-beginning-5gf9</link>
      <guid>https://dev.to/jackh404/a-never-ending-beginning-5gf9</guid>
      <description>&lt;p&gt;I have been a baker, an outdoor educator, and a cashier. I have been a plastics processing technician, an aircraft assembler, and a carpenter. I have studied acting, physics, and renewable energy. I have begun again and again and again, never being happier than when I am first learning a new skill. Most recently, I taught computer science in a public high school for a year. I got to have the ultimate beginner experience -- there is nothing quite like teaching while both learning to teach and learning your material at the same time. I also learned two very important lessons -- that I have an affinity for coding, and that I never want to work in a public high school again.&lt;/p&gt;




&lt;p&gt;So here I am once more, taking a crash course in HTML, CSS, JavaScript, React, Python, and Flask through Flatiron School. We have just finished our third week, with the first phase of the class culminating in a simple one-page web app designed to interact with an API. I have found that I really enjoy all the tinkering and troubleshooting -- the "wouldn't it be cool if" followed by figuring out how to get there. Any concern I had about losing interest as my rate of learning slows has completely fallen away as I have realized that coding is a literally bottomless fractal. Just as importantly, so is the community around it -- anywhere you turn, there is an expert in something, or even just an intrepid coder who figured out that thing I had been tearing my hair out over, who has already shared their knowledge. As time goes on and I learn more about whatever language(s) I wind up using most, more tools will be created, more languages will be written, and more literature will come out, forever expanding the field exponentially faster than any one person could keep up with. It is, in many ways, the ultimate expression of the role diversification and specialization that humanity has been working on for millenia -- and it affords mercurial fools like me the opportunity to be beginners for life.&lt;/p&gt;




&lt;h3&gt;
  
  
  PS: A question for seasoned devs
&lt;/h3&gt;

&lt;p&gt;One thing I have really been wondering about as I have gotten to write more interesting projects is global variables. I have heard they are somewhere between generally frowned upon and vehemently detested -- depending on who you ask -- but at this stage I am struggling to see why. I understand that an over-reliance on them would be sloppy and certainly cause the potential for name reuse and terrible bugs, but used well, it seems like they could reduce the issue of hot potatoing objects from function to function. When passing variables through function call after function call, I have created errors that could have been avoided if I had stored more information in the global context. Perhaps I am being too zealous in my separation of concerns, and should collapse multiple functions into one? At any rate, if you happen to read this, I would appreciate your thoughts.&lt;/p&gt;

</description>
      <category>beginners</category>
    </item>
  </channel>
</rss>
