<?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: luna-enamorada</title>
    <description>The latest articles on DEV Community by luna-enamorada (@lunaenamorada).</description>
    <link>https://dev.to/lunaenamorada</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%2F1059415%2F3c1d1a6a-d80b-419b-869c-b505d44163b0.png</url>
      <title>DEV Community: luna-enamorada</title>
      <link>https://dev.to/lunaenamorada</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lunaenamorada"/>
    <language>en</language>
    <item>
      <title>Designing REST APIs 📝</title>
      <dc:creator>luna-enamorada</dc:creator>
      <pubDate>Mon, 26 Jun 2023 10:48:22 +0000</pubDate>
      <link>https://dev.to/lunaenamorada/designing-rest-apis-ad9</link>
      <guid>https://dev.to/lunaenamorada/designing-rest-apis-ad9</guid>
      <description>&lt;h1&gt;
  
  
  What are REST APIs?
&lt;/h1&gt;

&lt;p&gt;Let's break it down. &lt;br&gt;
&lt;em&gt;What is an API?&lt;/em&gt;&lt;br&gt;
An API (Application Programming Interface) is a set of rules and protocals that allow different computer programs to communicate and interact with each other. An API acts as a messenger between the applications so they can do many things such as: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accessing Remote Services&lt;/li&gt;
&lt;li&gt;Data Integration&lt;/li&gt;
&lt;li&gt;Functionality Extension&lt;/li&gt;
&lt;li&gt;Customization &lt;/li&gt;
&lt;li&gt;Platform Interconnectivity&lt;/li&gt;
&lt;li&gt;Mobile App Development&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Cool, but what is REST?&lt;/em&gt; &lt;br&gt;
REST (Representational State Transfer) provides a consistant approach to designing and building an API. In REST, data can be identified by unique URLs. ( URIs, Uniform Resource Identifiers ) While REST isn't tied to HTTP, most REST APIs use HTTP as the application protocalls. So interactions occur though &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods"&gt;HTTP methods&lt;/a&gt;. &lt;/p&gt;

&lt;h1&gt;
  
  
  Best Practices for RESTFUL APIs ☝️🤓
&lt;/h1&gt;

&lt;p&gt;There is a huge emphasis on a uniform interface in regards to REST.&lt;/p&gt;

&lt;h2&gt;
  
  
  Path Names
&lt;/h2&gt;

&lt;p&gt;Some things to keep in mind when creating path names are: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use nouns&lt;/strong&gt;, try avoiding verbs. It should just represent the resoure instead of describing behavior. For example, &lt;code&gt;/resources&lt;/code&gt; instead of  &lt;code&gt;/getresource&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pluralize&lt;/strong&gt;, when a resource represents a collection. For example,&lt;code&gt;/books&lt;/code&gt; instead of &lt;code&gt;/book&lt;/code&gt;. If you want to represent a singluar book it would be &lt;code&gt;/books/&amp;lt;int:id&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Represent Hierachy for Related Resources&lt;/strong&gt;, the URI should reflect this. For example, &lt;code&gt;users/{userID}/posts&lt;/code&gt; represents posts relating to a specific user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Avoid Ambiguity but Keep it Short&lt;/strong&gt;, ambigous path names could cause confusion, same goes for longer URI names. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Versioning&lt;/strong&gt;, for when you need to show changes to the API by adding a version to the URI path. For example, &lt;code&gt;/v1/books&lt;/code&gt; and &lt;code&gt;/v2/books&lt;/code&gt; represents different versions.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Use JSON Format
&lt;/h2&gt;

&lt;p&gt;Using JSON (JavaScript Object Notation) format for RESTful APIs offers compatiability with RESTful principles. &lt;/p&gt;

&lt;h2&gt;
  
  
  Easy to Understand Responses
&lt;/h2&gt;

&lt;p&gt;Responses are crucial, some pointers for creating REST responses are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Appropriate Status Codes&lt;/strong&gt;, &lt;a href="https://www.restapitutorial.com/httpstatuscodes.html"&gt;HTTP status codes&lt;/a&gt; can quickly tell us what just occured with the request we executed. It also quickly let's us know errors in our requests. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clear Response Bodies&lt;/strong&gt;, will contain relevant data to the request. It should be in a consistant format throughout.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Handling&lt;/strong&gt;, you should be providing an informative error message in the response body with the appropriate HTTP status code. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security&lt;/strong&gt;, ensure that sensitive information is not displayed in the response body, implement data encryption to protect that data. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Rate Limiting
&lt;/h2&gt;

&lt;p&gt;Controlling the rate of requests to a web API ensures fair usage and protects the server from overload. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Clear Rate Limiting Policies&lt;/strong&gt;, clearly define the limits like the maximus number of requests allowed per minute per hour. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tie Authentication&lt;/strong&gt;, by requiring users to authenticate, you can monitor the number of requests and grant access to different endpoints.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Good Documentation
&lt;/h2&gt;

&lt;p&gt;Comprehensive documentation is important for successful useage of an API. The docs should be also publicly accessible. Some things to consider adding to your API docs are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Overview&lt;/strong&gt;, introduction, explaining the API's purpose, how to use the API, and the problem it solves. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Getting Started Instructions&lt;/strong&gt;, tells users how to obtain API key, provides any necessary sey up, and authentication methods.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resources and Endpoints&lt;/strong&gt;, lists all API resources and endpoints with a brief description. Includes their URLS, request methods, and expected response body. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Handling&lt;/strong&gt;, possibile error reponses the API might return, then provide specific error handling instructions. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rate Limiting and Catching Strategies&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tutorials&lt;/strong&gt;, adding real world examples and then tutorials on how your API can solve specific issues helps users get a better idea on what your API is used for. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keep it Up to Date!&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Sources! 🌐:
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.ibm.com/topics/rest-apis#:~:text=the%20next%20step-,What%20is%20a%20REST%20API%3F,representational%20state%20transfer%20architectural%20style."&gt;Four Principles for Designing Effective APIs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.redhat.com/en/topics/api/what-are-application-programming-interfaces"&gt;What is an API?&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.npmjs.com/package/express-rate-limit"&gt;Express Rate Limit&lt;/a&gt;&lt;br&gt;
&lt;a href="https://restfulapi.net/security-essentials/"&gt;REST API Security Essentials&lt;/a&gt;&lt;br&gt;
&lt;a href="https://blog.axway.com/learning-center/digital-security/keys-oauth/api-security-best-practices"&gt;API security: 12 essential best practices&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Basic OOP in Python 🐍📝</title>
      <dc:creator>luna-enamorada</dc:creator>
      <pubDate>Fri, 19 May 2023 09:56:35 +0000</pubDate>
      <link>https://dev.to/lunaenamorada/basic-oop-in-python-1iej</link>
      <guid>https://dev.to/lunaenamorada/basic-oop-in-python-1iej</guid>
      <description>&lt;p&gt;Object-Oriented Programming (OOP) is oriented around objects that typically represent real world concepts. Data is being prioritized rather than functionality.&lt;br&gt;
OOP provides a better way to structure and organize code, making it easier to read and maintain. You're essentially dividing up your program into small parts. &lt;/p&gt;

&lt;p&gt;What helped me solidify this concept is thinking in the literal sense. Since OOP is based on the real world, nothing is more real than you! (you are the realest) You are a person that has certain attributes that make you unique and behaviors. So let's start with that!&lt;/p&gt;
&lt;h2&gt;
  
  
  person.py
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MJ66toVa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w4z76jgrvq59pmfga83u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MJ66toVa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w4z76jgrvq59pmfga83u.png" alt="person.py" width="761" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First I started real easy by just naming the class. My first method is to initialize this new object with its attributes. The first parameter will always be &lt;code&gt;self&lt;/code&gt;. Self is a parameter that represents an instance of the class. It makes it so that we can access the attributes following up. Name and age are going to be our attributes for our person. &lt;br&gt;
In the body of our &lt;code&gt;__init__()&lt;/code&gt; method are 2 statements. &lt;br&gt;
&lt;code&gt;self.name = name&lt;br&gt;
self.age = age&lt;/code&gt;&lt;br&gt;
This is what is creating our attributes and assigns them with the value that is in the parameters. &lt;br&gt;
Next is a &lt;code&gt;greeting()&lt;/code&gt; method. It will just print out a greeting. Using some string interpolation it will also print out &lt;code&gt;self.name&lt;/code&gt; in the greeting. &lt;/p&gt;

&lt;p&gt;For the last 2 pieces of code, notice how I am now outside of my class. I'm creating an instance of the Person class. I just add in my name and age. Then I call a method from the Person class. &lt;/p&gt;

&lt;p&gt;So when I run my program I get back this 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;Hello! My name is Melissa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alright sweet, now we can think about all the different things we can do with this person. This person has limitless potential. But for now, let's just create a Student class for it to inherit Person from. &lt;br&gt;
Let's think about what attributes a student would need. A name, age, and major. &lt;/p&gt;
&lt;h2&gt;
  
  
  student.py
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z9dAtuZE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bapqdm6i42k81h5e106e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z9dAtuZE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bapqdm6i42k81h5e106e.png" alt="student.py" width="800" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The setup looks pretty similar to our Person. One major difference is the usage  of the &lt;code&gt;super()&lt;/code&gt; method. On the top, I imported our Person class since they're 2 different .py files. Person already has the attributes of name and age. So to avoid typing all of that code again, I can just inherit those attributes using the &lt;code&gt;super()&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;This time I added 2 student instances. And when I run &lt;code&gt;python3 student.py&lt;/code&gt; I get this in my terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello! My name is Melissa, I am 19, and I'm majoring in Software Engineering
Hello! My name is Kiana, I am 18, and I'm majoring in Law
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;This very basic idea can be further expanded upon. By thinking in objects, you can create classes that serve as blueprints. Our blueprint is the Person class. And then create other objects with similar attributes while still keeping the code DRY. Learning to incorporate OOP will make your coding more structured and easier to come back to. &lt;/p&gt;

&lt;p&gt;Great resources! :&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/self-in-python-class/"&gt;https://www.geeksforgeeks.org/self-in-python-class/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://realpython.com/python3-object-oriented-programming/"&gt;https://realpython.com/python3-object-oriented-programming/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.programiz.com/python-programming/methods/built-in/super"&gt;https://www.programiz.com/python-programming/methods/built-in/super&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Props in React ✨</title>
      <dc:creator>luna-enamorada</dc:creator>
      <pubDate>Fri, 28 Apr 2023 14:14:18 +0000</pubDate>
      <link>https://dev.to/lunaenamorada/props-in-react-4jb8</link>
      <guid>https://dev.to/lunaenamorada/props-in-react-4jb8</guid>
      <description>&lt;p&gt;Props (properties) are for communication among components. Think of it like an argument to functions. So this allows us to pass data between components using said props. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One thing to remember about passing props is that it is a unidirectional flow, the order should be: Parent ➡️ Child&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Let's try to pass some data down with props!
&lt;/h2&gt;

&lt;p&gt;So we'll say that our "App.js" is our parent function. (Typically this is on top of your component hierarchy)&lt;/p&gt;

&lt;p&gt;Here we'll also import our child component. So let's call it Header.&lt;br&gt;
Our goal here is to make Header more dynamic.&lt;/p&gt;

&lt;p&gt;Let's make a quick component hierarchy just so we can remember where we're at because things can get messy quick.&lt;/p&gt;

&lt;p&gt;├── App&lt;br&gt;
│   ├── Header&lt;/p&gt;

&lt;p&gt;Nothing too crazy here yet, but remember to stop and think about what component parents which. This will be very important in making your workflow a lot less painful.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Don't forget to import React&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  App.js
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import Header from './Header'

function App() {
    return (
    &amp;lt;div&amp;gt;
        &amp;lt;Header /&amp;gt;
    &amp;lt;/div&amp;gt;
    );
}

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

&lt;/div&gt;



&lt;p&gt;So this is how App is currently looking. I want to give it some props to pass down.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The syntax for creating props for a component is the same syntax as for writing attributes for an HTML tag.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import Header from './Header'

function App() {
    return (
    &amp;lt;div&amp;gt;
        &amp;lt;Header greeting="Hello" name="Mely"/&amp;gt;
    &amp;lt;/div&amp;gt;
    );
}

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

&lt;/div&gt;



&lt;p&gt;Now we have some props to pass down! Header now has access to the information we have stored in the attributes. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Note: Coolest thing about props is that they can be any data type, in this example it is a string data type.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's use this data in our Header component. &lt;/p&gt;

&lt;h2&gt;
  
  
  Header.js
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'

function Header(props) {
    return (
    &amp;lt;div&amp;gt;
        &amp;lt;h2&amp;gt;{props.greeting}!, my name is {props.name}.&amp;lt;/h2&amp;gt;
    &amp;lt;/div&amp;gt;
    );
}

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

&lt;/div&gt;



&lt;p&gt;Header takes in the props as an argument to the React function. You can gain access to the data by using dot notation. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Syntax of passing down the data is {props.insertNameOfPropHereLol}&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If dot notation is just too much for your keyboard, we could also pass down props using destructuring. Destructuring makes it possible to unpack the value into its own distinct variables.&lt;/p&gt;

&lt;h2&gt;
  
  
  Header.js
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'

function Header({greeting, name}) {
    return (
    &amp;lt;div&amp;gt;
        &amp;lt;h2&amp;gt;{greeting}!, my name is {name}.&amp;lt;/h2&amp;gt;
    &amp;lt;/div&amp;gt;
    );
}

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

&lt;/div&gt;



&lt;p&gt;The new syntax for the Header's argument is to wrap the specific props we want to pass down in a curly bracket{}. This makes our code so much easier to read and know what's going on. &lt;/p&gt;

&lt;p&gt;We did it!! We passed down information using props :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment"&gt;In depth on destructuring &lt;/a&gt;&lt;br&gt;
&lt;a href="https://refine.dev/blog/react-props/"&gt;React Props Explained with Examples&lt;/a&gt;&lt;br&gt;
&lt;a href="https://legacy.reurlactjs.org/docs/components-and-props.html"&gt;Components and Props&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Learning to work with the DOM</title>
      <dc:creator>luna-enamorada</dc:creator>
      <pubDate>Thu, 06 Apr 2023 12:34:21 +0000</pubDate>
      <link>https://dev.to/lunaenamorada/learning-to-work-with-the-dom-l4d</link>
      <guid>https://dev.to/lunaenamorada/learning-to-work-with-the-dom-l4d</guid>
      <description>&lt;p&gt;Before starting Flatiron's software engineering program, I completed my pre-work relying entirely on the tests to determine if I did what the tests asked me to do. It ended up being a series of events of me running the tests and seeing the red text and going from there. Never actually understanding what my current code was doing so wrong. &lt;/p&gt;

&lt;p&gt;While there was DOM manipulation in the prework, I had never really felt too comfortable using it at that point. Since I wasn't too confident in my skills I tended to stray from using it, only ever listening to the tests. &lt;/p&gt;

&lt;p&gt;Once starting the program and the tests are no longer in labs did it finally click that manipulating the DOM is a very useful tool.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do you access the DOM?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can access the DOM right now!😲&lt;/p&gt;

&lt;p&gt;Windows: ctrl + shift + i&lt;br&gt;
Mac: Option + Command +I &lt;/p&gt;

&lt;p&gt;We can see how this tab is showing us the structure and contents of this website. Opening up the DOM from your own document becomes more plentiful with the information. Presenting you with your code as well as the structure (HTML). &lt;br&gt;
You'll notice how the tab allows changes to be made onto the web page. This real time modification is what makes the DOM a handy tool. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What you can use this magical tab for:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Interacting with the DOM saves time from having to go back to your VS Code, change one line, then go back to the page, reload the page, see if anything changed.&lt;/p&gt;

&lt;p&gt;Initially, I didn't think much about what the DOM could do for me. I saw the page, saw what it did and didn't do, then went and changed the code to see if it'll do what I want it to do. I would stare at the screen for hours on end trying to figure out what I wasn't doing right. After a couple of lectures, I realized that I'm suffering needlessly when I could've been using &lt;code&gt;console.log()&lt;/code&gt; to see if my code even worked as intended. &lt;/p&gt;

&lt;p&gt;Constantly checking and making sure that the code I had written so far works the way I intended it to function. It has saved me so much time and mental energy. Before I felt like it was just me in a pitch-black room, arms stretched out, feeling for anything just to take one step and not fall on my face. &lt;/p&gt;

&lt;p&gt;Now if I need to pick out specific elements on the page I could easily hover over them to find their id highlighted in the HTML. Or even see silly spelling mistakes I missed, the console will tell me down to the exact line where it detected an error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson I learned&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Learning something new will always be an uncomfortable process. If you feel unsure about something, like I did with DOM, that is a good sign that you need to practice with it further. Esspecially if you're just starting out. Yes it's good you found something that feels comfortable but if there's a better way of doing it, it's worth the discomfort to  continue to flourish in your new journey. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
