<?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: Cristian Alaniz</title>
    <description>The latest articles on DEV Community by Cristian Alaniz (@cristian_alaniz).</description>
    <link>https://dev.to/cristian_alaniz</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%2F1214825%2Fdf23b2de-3b41-44e7-9ec9-02dcb25db945.png</url>
      <title>DEV Community: Cristian Alaniz</title>
      <link>https://dev.to/cristian_alaniz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cristian_alaniz"/>
    <language>en</language>
    <item>
      <title>Flask-Marshmallow vs. SQLAlchemy's SerializerMixin: Which One Should You Use?</title>
      <dc:creator>Cristian Alaniz</dc:creator>
      <pubDate>Thu, 30 Jan 2025 19:38:03 +0000</pubDate>
      <link>https://dev.to/cristian_alaniz/flask-marshmallow-vs-sqlalchemys-serializermixin-which-one-should-you-use-40gj</link>
      <guid>https://dev.to/cristian_alaniz/flask-marshmallow-vs-sqlalchemys-serializermixin-which-one-should-you-use-40gj</guid>
      <description>&lt;p&gt;When working with Flask and SQLAlchemy, serialization plays a crucial role in transforming database objects into JSON-friendly formats. Two popular approaches for handling this in Flask applications are Flask-Marshmallow and SQLAlchemy’s SerializerMixin. Each has its own strengths, so let’s break down how they compare.&lt;/p&gt;

&lt;h2&gt;
  
  
  SQLAlchemy’s SerializerMixin: A Quick and Easy Approach
&lt;/h2&gt;

&lt;p&gt;SQLAlchemy’s SerializerMixin is a convenient way to quickly add serialization capabilities to your models. By making your SQLAlchemy model inherit from SerializerMixin, you get the ability to easily convert objects to dictionaries and JSON.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Usage:&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;from flask_sqlalchemy import SQLAlchemy
from sqlalchemy_serializer import SerializerMixin

# Initialize SQLAlchemy
db = SQLAlchemy()

# Model definition
class User(db.Model, SerializerMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)

# Create an instance and serialize it
user = User(id=1, username='johndoe', email='johndoe@example.com')
print(user.to_dict())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pros:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Minimal Setup:&lt;/strong&gt; Just mix it into your model, and you’re good to go.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automatic Field Inclusion:&lt;/strong&gt; Includes all model fields in serialization by default, including any model relationships.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Works Well for Simple Use Cases:&lt;/strong&gt; Ideal when you just need a quick way to serialize models without additional customization.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cons:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Limited Customization:&lt;/strong&gt; Fine-tuning field output (e.g., excluding fields, formatting data) requires extra work.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tightly Coupled to the Model:&lt;/strong&gt; Since serialization logic is within the model itself, it can be less flexible when you need different output structures for different use cases.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Potential Overexposure of Data:&lt;/strong&gt; Since all fields are serialized by default, you might unintentionally expose sensitive data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Flask-Marshmallow: A More Flexible and Structured Approach
&lt;/h2&gt;

&lt;p&gt;Marshmallow, especially when used with Flask-Marshmallow, provides a more structured and explicit way to serialize and validate data. It separates serialization logic from the SQLAlchemy models, giving more control over how data is presented.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Usage:&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;from flask_marshmallow import Marshmallow
from flask_sqlalchemy import SQLAlchemy

# Initialize SQLAlchemy and Marshmallow
db = SQLAlchemy()
ma = Marshmallow()

# Model definition
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)

# Model Serialization Schema definition
class UserSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = User
        fields = ("id", "username")  # Only serialize these fields

# Create an instance and serialize it
user = User(id=1, username='johndoe', email='johndoe@example.com')
schema = UserSchema()
print(schema.dump(user))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pros:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Explicit Field Control:&lt;/strong&gt; You define exactly which fields to include, exclude, or modify.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Validation:&lt;/strong&gt; Supports validation rules to ensure data integrity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Customization &amp;amp; Nesting:&lt;/strong&gt; Easily customize field output and nest related objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Separation of Concerns:&lt;/strong&gt; Keeps serialization logic separate from the database model, making code more maintainable and reusable.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cons:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;More Boilerplate Code:&lt;/strong&gt; Requires defining schema classes separately from models.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Additional Learning Curve:&lt;/strong&gt; If you’re new to Marshmallow, understanding its concepts may take some time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Extra Dependency:&lt;/strong&gt; You need to install and maintain an additional library.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Which One Should You Choose?
&lt;/h2&gt;

&lt;p&gt;If you want a quick and simple way to serialize models without much customization, SerializerMixin is a great choice.&lt;/p&gt;

&lt;p&gt;If you need fine-grained control, validation, and a more maintainable approach, Flask-Marshmallow is the better option.&lt;/p&gt;

&lt;p&gt;For small projects or internal tools, SerializerMixin might be sufficient. However, for larger applications with complex data requirements, Flask-Marshmallow is often the more scalable and maintainable choice.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you wish to learn more about either one, check out these links:&lt;/em&gt;&lt;br&gt;
&lt;a href="https://pypi.org/project/sqlalchemy-serializer/" rel="noopener noreferrer"&gt;SerializerMixin&lt;/a&gt;&lt;br&gt;
&lt;a href="https://marshmallow.readthedocs.io/en/3.x-line/index.html" rel="noopener noreferrer"&gt;Marshmallow&lt;/a&gt;&lt;br&gt;
&lt;a href="https://flask-marshmallow.readthedocs.io/en/latest/" rel="noopener noreferrer"&gt;Flask-Marshmallow&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Confused about other topics in the article?&lt;/em&gt;&lt;br&gt;
&lt;a href="https://www.freecodecamp.org/news/what-is-serialization/" rel="noopener noreferrer"&gt;What is Serialization?&lt;/a&gt;&lt;br&gt;
&lt;a href="https://pythonbasics.org/what-is-flask-python/" rel="noopener noreferrer"&gt;What is Flask?&lt;/a&gt;&lt;br&gt;
&lt;a href="https://datascientest.com/en/sqlalchemy-what-is-it-whats-it-for" rel="noopener noreferrer"&gt;What is SQLAlchemy?&lt;/a&gt;&lt;/p&gt;

</description>
      <category>serialization</category>
      <category>flask</category>
      <category>sqlalchemy</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Flask Routes vs Flask-RESTful Routes</title>
      <dc:creator>Cristian Alaniz</dc:creator>
      <pubDate>Tue, 07 Jan 2025 07:45:12 +0000</pubDate>
      <link>https://dev.to/cristian_alaniz/flask-routes-vs-flask-restful-routes-2p1b</link>
      <guid>https://dev.to/cristian_alaniz/flask-routes-vs-flask-restful-routes-2p1b</guid>
      <description>&lt;p&gt;You probably have experience with basic flask routes if you are reading this. Perhaps you are new to the idea of routes and are curious about the differences and similarities. &lt;/p&gt;

&lt;p&gt;In this article i'd like to compare flask routes and flask-restful routes on a &lt;strong&gt;&lt;em&gt;syntactical level&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What are Routes?
&lt;/h2&gt;

&lt;p&gt;Routes are made up of 3 key components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;URL Path&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Server Resource&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HTTP Methods&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They are used as &lt;em&gt;communication channels&lt;/em&gt; between a client and a server.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  URL Path
&lt;/h2&gt;

&lt;p&gt;In both regular flask routes and restful routes the URL path is the specific address on the server that the client requests. An example could be '/home'.&lt;/p&gt;

&lt;p&gt;The difference lies in &lt;strong&gt;&lt;em&gt;how&lt;/em&gt;&lt;/strong&gt; they are defined.&lt;/p&gt;

&lt;h4&gt;
  
  
  Flask Routes
&lt;/h4&gt;

&lt;p&gt;Defining a URL path in a flask route using the home example would look like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@app.route('/home')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The actual URL path is passed an argument to the route method. &lt;/p&gt;

&lt;p&gt;The decorator is used to bind a function (which is declared under this line and will be discussed shortly) to the URL path.&lt;/p&gt;

&lt;h4&gt;
  
  
  Flask-RESTful Routes
&lt;/h4&gt;

&lt;p&gt;Defining a URL path via a restful route would look like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;api.add_resource(Home, '/home')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The URL path is passed as the second argument to the add_resource method. &lt;/p&gt;

&lt;p&gt;The first argument is the server resource associated with the URL path.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Server Resource
&lt;/h2&gt;

&lt;p&gt;This is where the magic happens. The logic and actions are defined here. Each resource receives a request and returns the appropriate response.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;key difference&lt;/em&gt; lies in the way flask and flask-restful &lt;em&gt;think&lt;/em&gt; about the server resource.&lt;/p&gt;

&lt;h4&gt;
  
  
  Flask Routes
&lt;/h4&gt;

&lt;p&gt;With a regular flask route, the "server resource" is a &lt;strong&gt;&lt;em&gt;function&lt;/em&gt;&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;def home():
    return "Welcome to the homepage!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Flask-RESTful Routes
&lt;/h4&gt;

&lt;p&gt;Flask-RESTful takes a &lt;strong&gt;&lt;em&gt;class-based&lt;/em&gt;&lt;/strong&gt; approach to defining a "server resource". The class inherits from the RESTful class Resource.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Home(Resource):
    def get(self):
        return "Welcome to the homepage!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcm0qj7oa43vd7fzri0na.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcm0qj7oa43vd7fzri0na.jpeg" alt="HTTP Methods" width="348" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  HTTP Methods
&lt;/h2&gt;

&lt;p&gt;Last but not least, &lt;em&gt;both&lt;/em&gt; flask routes and restful routes take HTTP methods. These methods help to further specify a clients request, ensuring the request is handled by the correct server resource.&lt;/p&gt;

&lt;p&gt;Once more, the route types differ in &lt;em&gt;how&lt;/em&gt; they define HTTP methods.&lt;/p&gt;

&lt;h4&gt;
  
  
  Flask Routes
&lt;/h4&gt;

&lt;p&gt;Flask routes takes the approach of defining HTTP methods in the same space where it defines the URL Path. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;@app.route('/home', methods=['GET'])&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Flask-RESTful Routes
&lt;/h4&gt;

&lt;p&gt;Flask-RESTful takes the approach of defining each HTTP method as a method of the server resource class.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;def get(self):&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You may have caught this in the server resource example.&lt;/p&gt;




&lt;h2&gt;
  
  
  All Together
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Flask Route Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/home', methods=['GET'])
def home():
    return "Welcome to the homepage!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Flask-RESTful Route Example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Home(Resource):
    def get(self):
        return "Welcome to the homepage!"

api.add_resource(Home, '/home')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Flask routes and Flask-RESTful routes are both viable options to establish communication between a client and a server. &lt;/p&gt;

&lt;p&gt;Beware as there are still a lot of differences we didn't cover. One big difference is that regular flask routes do &lt;strong&gt;not&lt;/strong&gt; follow REST principles but can be made to follow them unlike their counterpart that naturally do. Other differences include regular Flask compared to Flask-RESTful and configuration, among other things.&lt;/p&gt;

&lt;p&gt;Check out these articles to dive deeper into the differences:&lt;br&gt;
&lt;a href="https://www.mulesoft.com/api/what-is-an-api" rel="noopener noreferrer"&gt;What is an API&lt;/a&gt;&lt;br&gt;
&lt;a href="https://codewords.recurse.com/issues/five/what-restful-actually-means" rel="noopener noreferrer"&gt;What RESTful Actually Means&lt;/a&gt;&lt;br&gt;
&lt;a href="https://flask.palletsprojects.com/en/latest/quickstart/#routing" rel="noopener noreferrer"&gt;Setting up Flask&lt;/a&gt;&lt;br&gt;
&lt;a href="https://flask-restful.readthedocs.io/en/latest/" rel="noopener noreferrer"&gt;Setting up Flask-RESTful&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods" rel="noopener noreferrer"&gt;HTTP methods&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flask</category>
      <category>restful</category>
      <category>python</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Regular Expressions</title>
      <dc:creator>Cristian Alaniz</dc:creator>
      <pubDate>Thu, 10 Oct 2024 09:21:56 +0000</pubDate>
      <link>https://dev.to/cristian_alaniz/regular-expressions-1fmc</link>
      <guid>https://dev.to/cristian_alaniz/regular-expressions-1fmc</guid>
      <description>&lt;p&gt;Picture this, you are attempting to sign up for a website, you enter your email and password and you get the message "The username or password you entered is invalid. Please try again." &lt;/p&gt;

&lt;p&gt;How exactly does the computer know the username or password you input is invalid? The answer is a super powerful tool called &lt;strong&gt;regular expression&lt;/strong&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Regular Expression?
&lt;/h2&gt;

&lt;p&gt;A regular expression, or &lt;strong&gt;regex&lt;/strong&gt; for short, is a pattern that is used to match all types of characters in a text. The beauty of a regular expression is that you can design it to search for anything you want. &lt;/p&gt;

&lt;h2&gt;
  
  
  How RegEx Patterns Work
&lt;/h2&gt;

&lt;p&gt;RegEx patterns can be as simple as searching for character(s) in a text, with an exact full match. For example the pattern:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;password&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Would match with the literal text "password". This particular pattern is case sensitive so the text "Password" would not match since the p is capitalized.&lt;/p&gt;

&lt;h2&gt;
  
  
  Complex RegEx Patterns
&lt;/h2&gt;

&lt;p&gt;Most websites require your password to meet these requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Must contain a lowercase letter&lt;/li&gt;
&lt;li&gt;Must contain a capital letter&lt;/li&gt;
&lt;li&gt;Must contain a digit&lt;/li&gt;
&lt;li&gt;Must contain a non-word character&lt;/li&gt;
&lt;li&gt;Must be at least 8 characters long&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How would we go about making a pattern that searches for these requirements? The key lies in regex metacharacters. &lt;strong&gt;&lt;em&gt;Metacharacters&lt;/em&gt;&lt;/strong&gt; are pre-defined shorthands to match a type of character. &lt;/p&gt;

&lt;h2&gt;
  
  
  Meeting The Requirements
&lt;/h2&gt;

&lt;p&gt;The metacharacter we can use to pass the first requirement is: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;[a-z]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The brackets are used to tell the computer where the range starts and ends. a-z is used to search for lowercase letters in the a-z range. &lt;/p&gt;




&lt;p&gt;&lt;code&gt;[A-Z]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Similar to a-z, A-Z searches for any capitalized letters. Passing the second requirement.&lt;/p&gt;




&lt;p&gt;&lt;code&gt;\d&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This metacharacter passes the third requirement, it tells the computer to search and match with any digit.&lt;/p&gt;




&lt;p&gt;&lt;code&gt;\W&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This metacharacter can be used to pass the fourth argument because it matches any non-word character. Word characters include any letter capitalized or not, any digit, and an underscore. &lt;/p&gt;




&lt;p&gt;&lt;code&gt;{8,}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The curly brackets are special characters that tell the computer to match whatever came before it x amount of times. If a comma is included inside the brackets it changes to match whatever came before &lt;em&gt;at least&lt;/em&gt; x amount of times. If a second number is put after the comma it will the preceded pattern a maximum of y times. If no number is put after the comma, the computer interprets it as an infinite amount. &lt;/p&gt;

&lt;h2&gt;
  
  
  Putting It All Together
&lt;/h2&gt;

&lt;p&gt;With the help of some additional metacharacters:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;^&lt;/code&gt; Used to indicate the beginning of a text&lt;br&gt;
&lt;code&gt;$&lt;/code&gt; Used to indicate the end of a text&lt;br&gt;
&lt;code&gt;()&lt;/code&gt; Used to group expressions&lt;br&gt;
&lt;code&gt;(?=)&lt;/code&gt; Used to lookahead in a text&lt;br&gt;
&lt;code&gt;.&lt;/code&gt; Matches any character&lt;br&gt;
&lt;code&gt;*&lt;/code&gt; Matches the previous token between 0 and unlimited times&lt;/p&gt;

&lt;p&gt;We can now put our password regex pattern together. The final result will look like this. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*\W).{8,}$&lt;/code&gt;&lt;/p&gt;

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

&lt;p&gt;At this point you probably realized just how powerful regular expressions can be. This is just the tip of the iceberg. They can be used to validate input, match text, search and replace text, amongst other things. &lt;/p&gt;

&lt;p&gt;If this article peaked your interest, I recommend you check out some of the links below. &lt;/p&gt;

&lt;p&gt;To learn more about regular expressions check out these articles: &lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions" rel="noopener noreferrer"&gt;Regular Expressions&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developers.google.com/edu/python/regular-expressions" rel="noopener noreferrer"&gt;Python Regular Expressions-Google Education&lt;/a&gt;&lt;br&gt;
To experiment writing your own regular expressions visit &lt;a href="https://regex101.com/" rel="noopener noreferrer"&gt;regex101&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.oreilly.com/content/wp-content/uploads/sites/2/2019/06/email-regex_crop-ae942dc427c8cebd3a83c52d17389123.jpg" rel="noopener noreferrer"&gt;Wallpaper source&lt;/a&gt;&lt;/p&gt;

</description>
      <category>regex</category>
      <category>webdev</category>
      <category>softwaredevelopment</category>
      <category>python</category>
    </item>
    <item>
      <title>Vanilla JS vs REACT JS</title>
      <dc:creator>Cristian Alaniz</dc:creator>
      <pubDate>Wed, 20 Mar 2024 03:59:43 +0000</pubDate>
      <link>https://dev.to/cristian_alaniz/vanilla-js-vs-react-js-4j4l</link>
      <guid>https://dev.to/cristian_alaniz/vanilla-js-vs-react-js-4j4l</guid>
      <description>&lt;p&gt;If you're reading this, you are probably familiar with Vanilla JavaScript. You use no outside resources, just plain old JavaScript along with HTML and CSS to get the job done. What if I told you there was a different way to get the job done while using JS principles? Well there is, it's called REACT. REACT is a library that is an extension of JavaScript. There are many differences between the two but I would like like to focus on 3 for the rest of the article.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functions vs Components&lt;/li&gt;
&lt;li&gt;Parameters/Arguments vs Props&lt;/li&gt;
&lt;li&gt;What they Return&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Functions VS Components
&lt;/h2&gt;

&lt;p&gt;How do we declare a function in JavaScript? It's pretty simple.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function example(exampleParameter) {
  //example code
  return exampleParameter
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Function Example&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There a few parts to this declaration. We use the string "function" to tell the program that we are about to declare a function. Next is the function name "example". After that comes "(exampleParameter)" syntax to declare any parameters the function may have. Lastly we have the code block inside the curly brackets "{}" with a return statement.&lt;/p&gt;

&lt;h3&gt;
  
  
  How does this differ from a REACT component?
&lt;/h3&gt;

&lt;p&gt;A REACT component has a very similar structure to a function. The main differences being that a component name is Capitalized, takes in props instead of arguments, and it returns JSX. The name is Capitalized so that the engine can tell the difference between a function and component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ExampleComponent({ props }) {
  return (
    &amp;lt;p&amp;gt;{props.variable1}, {props.variable2}&amp;lt;/p&amp;gt;
  )
}

export default ExampleComponent;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Component Example&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Parameters/Arguments vs Props
&lt;/h2&gt;

&lt;p&gt;You might have noticed in the &lt;strong&gt;&lt;em&gt;Component Example&lt;/em&gt;&lt;/strong&gt; that where a function declares parameters, a component declares a props variable.&lt;/p&gt;

&lt;p&gt;So how are they similar? They are similar in the sense that they both allocate a space where data can be passed in.&lt;/p&gt;

&lt;p&gt;Their difference lies in the way they are passed in. With Vanilla JS you simply have to call the function and pass in the arguments. With a REACT component, the approach is different.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//App.js
import ExampleComponent from "./ExampleComponent"

function App() {
  const variable1 = "Hello";
  const variable2 = 7;

  return (
    &amp;lt;ExampleComponent props={variable1, variable2} /&amp;gt;
  )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Passing Props To Component&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the example above we are passing variables into a props object. This object will hold all the props we are trying to pass to ExampleComponent component.&lt;/p&gt;

&lt;p&gt;Now how do we get access to these props inside the ExampleComponent component? The answer lies in an earlier example: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;function ExampleComponent({ props })&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The component allocates space for props inside the parenthesis, which are also enclosed in curly brackets for destructuring purposes. Keep in mind that the name of the passed in prop(s) (&lt;em&gt;Passing Props To Component&lt;/em&gt;) has to be identical to the declared prop(s) (&lt;em&gt;Component Example&lt;/em&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Return
&lt;/h2&gt;

&lt;p&gt;Another thing you might have noticed comparing the function and component example is the fact that they return different things. A function can return a lot of things, but to sum it all up, it returns a value. A component on the other hand returns JSX.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's JSX?
&lt;/h3&gt;

&lt;p&gt;JSX or JavaScript XML is an extension of JavaScript that allows you to write HTML like code. This code can be written directly into JavaScript, where it is translated back into Vanilla JavaScript by a tool like Babel before being executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A couple things to know about JSX:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It allows you to mix JS expressions with JSX&lt;/li&gt;
&lt;li&gt;All JSX code must be engulfed by a some opening and closing tag&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the &lt;em&gt;Component Example&lt;/em&gt; we have an example of both these! &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;{props.variable1}, {props.variable2}&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The p tags at the beginning and end of the code are examples of opening and closing tags. It's done this way to allow the JS engine to clearly and easily organize all the JSX when it comes times to bring it all together.&lt;/p&gt;

&lt;p&gt;Inside of the tags are two examples JS expressions being mixed with JSX. &lt;strong&gt;&lt;em&gt;{props.variable1}, {props.variable2}&lt;/em&gt;&lt;/strong&gt; are JS expressions holding a value. This value is then plugged into the JSX output and Voila. All thanks to curly brackets that allow this mix to happen. &lt;/p&gt;

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

&lt;p&gt;There are a lot of other differences between the two. For instance what's up with "import" and "export default"?! Why is ComponentExample able to be returned in App.js? There are a lot of mysteries left to unravel but one thing is for sure, REACT can be a powerful tool. If you're interested in finding out more, I recommend you check out one of the links.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://react.dev/learn/importing-and-exporting-components"&gt;Importing and Exporting Components&lt;/a&gt;&lt;br&gt;
&lt;a href="https://react.dev/learn"&gt;Free React Course&lt;/a&gt;&lt;br&gt;
&lt;a href="https://react.dev/blog/2023/03/16/introducing-react-dev"&gt;REACT Website&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What Makes Up a Website?</title>
      <dc:creator>Cristian Alaniz</dc:creator>
      <pubDate>Fri, 19 Jan 2024 05:45:43 +0000</pubDate>
      <link>https://dev.to/cristian_alaniz/what-i-learned-from-my-phase-1-project-613</link>
      <guid>https://dev.to/cristian_alaniz/what-i-learned-from-my-phase-1-project-613</guid>
      <description>&lt;p&gt;You probably navigate the internet everyday without thinking about it. Visiting different websites, clicking on many links, etc. Have you ever stopped and asked yourself, what makes up a website? &lt;/p&gt;

&lt;p&gt;To explain what makes up a website in simple terms, I will use a car analogy going forward. Try and keep up!&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Needed To Make A Website?
&lt;/h2&gt;

&lt;p&gt;To make a website is surprisingly simple, all you need are the following: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Structure (HTML)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Functionality (JavaScript)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Style (CSS)&lt;/em&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;HyperText Markup Language (HTML)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A car needs a frame, chassis, axels, pedals, steering wheel etc. All of these put together make up the cars structure. Similarly, a websites structure is an HTML document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;!-- head HTML --&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;!-- body HTML --&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do these tags mean? The "&lt;u&gt;!DOCTYPE&lt;/u&gt;" tag states the type of document. In this case, it's an HTML. &lt;/p&gt;

&lt;p&gt;Next in line is the "&lt;u&gt;html&lt;/u&gt;" tag. This tag, like most HTML tags, has an opening and closing tag. The closing tag syntax is the same as the opening syntax except it has a "/", signifying a closing tag. It's purpose is to act as a container for all other tags inside the document.&lt;/p&gt;

&lt;p&gt;The "&lt;u&gt;head&lt;/u&gt;" tag contains machine readable information. Examples of this would be the title, script(s), or style sheet(s). All contents inside this tag cannot be seen when you load a website.&lt;/p&gt;

&lt;p&gt;Last but certainly not least we have the "&lt;u&gt;body&lt;/u&gt;" tag. This tag contains all of the content that you see when you load up a website. You can add all sorts of things inside of it such as images, text, shapes, this is your canvass.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Functionality (JavaScript)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you have the cars structure, it's time to make things have functionality. For example, when the steering wheel is turned left, make the steering axel turn to the left. When the horn is pressed, make a noise!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What if we wanted to make a header change colors when the mouse cursor overlooks it and revert to its original color when the mouse cursor is off the header?&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;html:
&amp;lt;body&amp;gt;
  &amp;lt;h1&amp;gt;Header&amp;lt;/h1&amp;gt;
&amp;lt;/body&amp;gt;

JavaScript:
const h1 = document.querySelector("h1");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We start off assigning the header to a h1 variable. &lt;/p&gt;

&lt;p&gt;Now we can add a "&lt;u&gt;mouseover&lt;/u&gt;" event to the selected header.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;h1.addEventListener("mouseover", () =&amp;gt; h1.style.color = "red");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using .addEventListener to do so, we have successfully turned the header red. .addEventListener takes in two arguments, an event, in this case "mouseover", and a callback function. &lt;/p&gt;

&lt;p&gt;We still need to revert the color back to it's original color when the mouse is not on the header.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;h1.addEventListener("mouseout", () =&amp;gt; h1.style.color = "white");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similar to the previous code, we have successfully turned the header back to its original color (white) when the mouse is not over the header using the "&lt;u&gt;mouseout&lt;/u&gt;" event.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffjj2qmqwzlnqfqvg13zq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffjj2qmqwzlnqfqvg13zq.gif" alt="A header that turns red when the mouse is over it and white when the mouse is not over it" width="426" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cascadia Style Sheets (CSS)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that we have a fully functional car with structure, we can customize it any way we want. You can add stickers to it, give it a spoiler, add unique headlights, and make it any color you desire! This is where CSS comes in, allowing you to style your website anyway you want.&lt;/p&gt;

&lt;p&gt;There are 3 ways to assign style to an element. The first and most broad way to do it is by using the &lt;u&gt;tag name&lt;/u&gt;. Any style assigned to this tag name will apply to all tags with the same name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTML:
&amp;lt;div&amp;gt;
  &amp;lt;h1&amp;gt;Header 1&amp;lt;/h1&amp;gt;
  &amp;lt;h1 class="with-border"&amp;gt;Header 2&amp;lt;/h1&amp;gt;
  &amp;lt;h1 class="with-border" id="red"&amp;gt;Header 3&amp;lt;/h1&amp;gt;
&amp;lt;/div&amp;gt;

CSS:
h1 {
font-size: 50px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This CSS syntax sets the font size of all h1 elements to 50px.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F86mlcf45jlbzrqnuuk0t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F86mlcf45jlbzrqnuuk0t.png" alt="Headers with h1 CSS" width="236" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The next option goes one layer deeper, only applying the style to the HTML tags with the same &lt;u&gt;class name&lt;/u&gt; (i.e. "with-border"). Notice that the "with-border" has a period (.), signifying that it is a class name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CSS:
.with-border {
border: 1px solid white;
height: fit-content;
width: fit-content;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The "border" style takes in a number value that sets the border's thickness as well as a color. In this case the border's thickness is 1px. Both the "height" and "width" are set to fit-content, allowing the border to be snug against the element.&lt;/p&gt;

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

&lt;p&gt;The final option is the most accurate due to the &lt;u&gt;id value&lt;/u&gt; being unique to that element (i.e. "red"). The id name has a # before it, signaling an id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CSS:
#red {
color: red;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thus setting the element's color to red.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F50t22984grq7eqq5yipx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F50t22984grq7eqq5yipx.png" alt="Header with id CSS" width="231" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Big Takeaway&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Who knew a car and a website could be so similar? HTML, JavaScript, and CSS are very powerful tools used to make all sorts of websites with different purposes. These languages make up what is known as &lt;em&gt;Front End Development&lt;/em&gt;. To put it shortly, you develop the part that people will see when they go to a websites URL. &lt;/p&gt;

&lt;p&gt;There is a whole other side of the coin called &lt;em&gt;Back End Development&lt;/em&gt;. This is the side that you don't see but is equally as important. If you are curious about how they work together, check out the blog below!&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Want to learn more about the differences? Check out this blog:&lt;/strong&gt; &lt;a href="https://flatironschool.com/blog/front-end-vs-back-end-development/" rel="noopener noreferrer"&gt;Front End vs Back End Development&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GIF sources:&lt;/strong&gt; &lt;br&gt;
&lt;a href="https://i.pinimg.com/originals/5f/08/50/5f08505655b858d52ea4ef07a6fa58d5.gif" rel="noopener noreferrer"&gt;Cover Image&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.giphy.com/media/nqYXNf3aK6EvK/giphy.gif" rel="noopener noreferrer"&gt;Lightning McQueen&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>javascript</category>
      <category>css</category>
    </item>
  </channel>
</rss>
