<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Matthew Lui on Medium]]></title>
        <description><![CDATA[Stories by Matthew Lui on Medium]]></description>
        <link>https://medium.com/@lui.matthew?source=rss-f107b6484c5f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*D3IIWAeGi2hkuV9v</url>
            <title>Stories by Matthew Lui on Medium</title>
            <link>https://medium.com/@lui.matthew?source=rss-f107b6484c5f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 08:24:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lui.matthew/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Rails Serializers]]></title>
            <link>https://medium.com/@lui.matthew/rails-serializers-3af496e43d11?source=rss-f107b6484c5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3af496e43d11</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[serializers]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Matthew Lui]]></dc:creator>
            <pubDate>Tue, 03 Jan 2023 01:44:28 GMT</pubDate>
            <atom:updated>2023-01-03T02:03:19.686Z</atom:updated>
            <content:encoded><![CDATA[<p>Serializers are useful in Rails because they allow you to control how model objects are converted to JSON or other formats when returned in an API response. Serializers are useful for a variety of reasons.</p><p>• Serializers allow you to specify which model object attributes should be included in the serialized representation. This is useful if you want to conceal sensitive data or only include a subset of the available data.</p><p>• Serializers allow you to specify how you want the attributes formatted. For example, you may want to format a date attribute differently, or you may want to include or exclude associations when serializing the object.</p><p>• Serializers enable you to write custom logic to transform data before serialization. If you need to perform calculations or transformations on the data before it is returned in the API response, this can be useful. By moving the logic for serializing data out of those layers and into a separate object, serializers can help you keep your controllers and views clean and focused.</p><p>Here are a few examples of how you might use a serializer in a Rails application:</p><ol><li>Basic serialization:</li></ol><pre>class UserSerializer &lt; ActiveModel::Serializer<br>  attributes :id, :name, :email<br>end</pre><p>This would generate a JSON object that includes the <strong>id,</strong> <strong>name,</strong> and <strong>email</strong> attributes for a user model.</p><p>2. Serialization with associations:</p><pre>class UserSerializer &lt; ActiveModel::Serializer<br>  attributes :id, :name, :email<br>  has_many :posts<br>end<br><br>class PostSerializer &lt; ActiveModel::Serializer<br>  attributes :id, :title, :body<br>end</pre><p>3. Serialization with custom logic</p><pre>class UserSerializer &lt; ActiveModel::Serializer<br>  attributes :id, :name, :email<br>  attribute :naruto_avatar do<br>    &quot;https://avatars.alphacoders.com/avatars/view/94610/#{object.email_hash}&quot;<br>  end<br>end</pre><p>In this example, the user serializer includes a custom attribute called <strong>naruto_url</strong>, which is generated using the <strong>email_hash</strong> attribute of the user model. This allows you to include data in the JSON response that may not be directly stored in the model&#39;s attributes.</p><p>Here are my sources</p><p><a href="https://api.rubyonrails.org/classes/ActiveModel/Serialization.html">Rubyonrails</a></p><p><a href="https://www.educative.io/answers/what-are-serializers-in-ror">educative</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3af496e43d11" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RESTful API]]></title>
            <link>https://medium.com/@lui.matthew/restful-api-5b55d2e2918e?source=rss-f107b6484c5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b55d2e2918e</guid>
            <category><![CDATA[full-stack]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[full-stack-developer]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Matthew Lui]]></dc:creator>
            <pubDate>Tue, 13 Dec 2022 08:41:39 GMT</pubDate>
            <atom:updated>2022-12-13T17:31:52.504Z</atom:updated>
            <content:encoded><![CDATA[<p>Common best practices for a RESTful API</p><p><strong>What is REST?</strong></p><p>REST stands for <strong>RE</strong>presentational <strong>S</strong>tate<strong> T</strong>ransfer. Roy Fielding created this architecture in 2000 to guide the design of web architecture. It’s one of the most common computer communication architectures for communication over the internet.</p><p><strong>What is API ?</strong></p><p>API stands for Application Programming Interface.</p><p>API is how our client (frontend) communicates with server (backend).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*YPNBlKA7EUeULHEX5VI7aQ.png" /></figure><p>A restful API organizes resources into a unique set of URIs (uniform resource identifier),</p><p>In our URL example below, our resource is the movies in our database.</p><pre>http:localhost9292:/movies</pre><p><a href="https://www.codecademy.com/article/what-is-rest"><strong><em>Statelessness</em></strong></a></p><p>Systems that follow the REST paradigm are stateless, meaning that the server does not need to know anything about what state the client is in and vice versa. In this way, both the server and the client can understand any message received, even without seeing previous messages.</p><h3><strong>Common practices for REST API</strong></h3><p><strong>Using JSON as the format in sending and receiving data</strong></p><p>JSON stands for Javascript Object Notation.</p><p>Many languages uses JSON as a medium to send and receive information. Some languages include C+, C++, C#, PHP, Python, Ruby.</p><p><strong>The endpoint of our request should be a noun and not a verb.</strong></p><p>Our CRUD (CREATE, READ, UPDATE, DELETE) is responsible for performing operations.</p><p>correct REST practice</p><pre>http:localhost9292/characters</pre><p>incorrect REST practice</p><pre>http:localhost9292/getAllCharacters</pre><p><strong>Always name our collections with Plurals</strong></p><p>By pluralizing our data, it lets our users know there are additional exercises in our collection.</p><p>Incorrect REST practice</p><pre>http:localhost9292/exercise/12</pre><p>Correct REST practice</p><pre>http:localhost9292/exercises/12</pre><p><strong>Use Status Codes in handling errors.</strong></p><p>We should always use standardize status codes for responses to request</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*-uG5lyVEHYNT5t9gJWdiBA.png" /></figure><p><strong>Using Nesting on endpoints to Show relationships</strong></p><p>Here’s an example of using nesting to show relationships/associations.</p><pre>http:localhost9292/artists/songs</pre><p>We should avoid nesting more than 3 levels deep.</p><pre>http:localhost9292/artist/songs/biography/comments</pre><p><strong>Use Filtering, Sorting and Pagination to retrieve data request.</strong></p><p><em>Pagination</em></p><p>When we have large sets of data, we can use the limit and offset to limit the results if the request doesn’t clearly define limits</p><pre>http:localhost9292/movies?limit=25&amp;offset=50<br></pre><p><em>Offset </em>— An offset is number of records you wish to skip before selecting records</p><p><em>Limit </em>— limit controls the maximum results to be returned.</p><p><em>Filter/Sorting</em></p><p>An example of a filtered endpoint is the one below:</p><pre>https://mysite.com/posts?tags=javascript</pre><p>This endpoint will fetch any post that has a tag of JavaScript.</p><p><strong>Semantic versioning (SemVer)</strong></p><p>SemVer is a universal way for number the release of the software or the version of the site.</p><p>The current version of React Router is 6.4.5</p><p>· The <strong>6</strong> represents the major version (major overhaul of application)</p><p>· The <strong>4 </strong>represents the minor version (features added)</p><p>· The <strong>5</strong> represents the patch (any fixes to bugs)</p><pre>https://flatster.com/v1/listings</pre><pre>https://flatster.com/v2/listings</pre><p><strong>Configuring SSL in your application.</strong></p><p>The primary reason we incorporate SSL in our application is the secure sensitive information. A way we can incorporate SSL in our application is setting up user name and password authentication.</p><p>Secured URL https:localhost3000/movies</p><p>Unsecured URL http:localhost9292/movies</p><p>Some useful resources to learn more about REST API as well as my references.</p><p><a href="https://learn.microsoft.com/en-us/azure/architecture/best-practices/api-design">Microsoft</a></p><p><a href="https://www.guru99.com/restful-web-services.html">GURU99</a></p><p><a href="https://restfulapi.net/resource-naming/">Restfulapi.net</a></p><p><a href="https://help.sap.com/docs/SAP_ASE/e0d4539d39c34f52ae9ef822c2060077/26d84b4ddae94fed89d4e7c88bc8d1e6.html?version=16.0.4.0">SAP pagination</a></p><p><a href="https://www.freecodecamp.org/news/rest-api-best-practices-rest-endpoint-design-examples/">freecodecamp</a>.</p><p><a href="http://Statelessness Systems that follow the REST paradigm are stateless, meaning that the server does not need to know anything about what state the client is in and vice versa. In this way, both the server and the client can understand any message received, even without seeing previous messages.">Codeacademy</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b55d2e2918e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ruby Enumerable]]></title>
            <link>https://medium.com/@lui.matthew/ruby-enumerable-dc4ff2f3dd60?source=rss-f107b6484c5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc4ff2f3dd60</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[fullstack-development]]></category>
            <dc:creator><![CDATA[Matthew Lui]]></dc:creator>
            <pubDate>Tue, 06 Dec 2022 16:25:50 GMT</pubDate>
            <atom:updated>2022-12-06T17:19:05.325Z</atom:updated>
            <content:encoded><![CDATA[<p>Moving from Front End programming to Back End programming was challenging. What I enjoyed most about Javascript and React is the ability to test our code in our browser console as well as seeing our page render based on changes in state. With ruby programming, the methods are tested with ruby tools like rake console and binding.pry</p><p>What I found very useful in Ruby programming is the enumerable modules</p><p>What are Ruby Enumerable?</p><p>Enumerable allows the sorting, searching and traversal through our collection of data.</p><p>Some familiar enumarable that we used in Javascript are .filter, .each, .map.</p><p>Is there a difference between an enumerator and an enumerable?</p><p>An enumerator allows you to instantiate an instance in our code using an enumerable without a block of code.</p><pre>[1, 2, 3].each</pre><p>The great thing about Ruby is that there are many enumerable to help evaluate our data. Here are a few enumerable I found easiser to understand that could be useful.</p><p>Minmax_by</p><p>Evaluates our data and returns the min and max values in our code</p><pre>superheroes = (superman, batman, aquaman, wonderwoman)<br>superheroes.minmax_by { |x| x.length } #=&gt; [&quot;batman&quot;, &quot;wonderwoman&quot;]</pre><p>.reject</p><p>Returns a collection of elements in our array that has a condition of false</p><pre>[1, 2, 3, 4, 5].reject { |num| num.even? } #=&gt; [1, 3, 5]</pre><p>.drop</p><p>Drops the first element we evaluate and returns the rest of the elements in our array.</p><pre>num = [1, 2, 3, 4, 5, 0]<br>num.drop(3)#=&gt; [4, 5, 0]</pre><p>Take_while</p><p>Our code stops iterating once it returns nil or false</p><pre>a = [1, 2, 3, 4, 5, 0]<br>a.take_while { |i| i &lt; 3 } #=&gt; [1, 2]</pre><p>Here the links that I referenced for my blog.</p><p><a href="https://ruby-doc.org/core-2.5.1/Enumerable.html">Ruby-Docs.org</a></p><p><a href="https://docs.ruby-lang.org/en/2.0.0/Enumerable.html">Docs.ruby-lang.org</a></p><p><a href="https://api.rubyonrails.org/classes/Enumerable.html">Api.rubyonrails.org</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc4ff2f3dd60" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Controlled Inputs and Forms in React]]></title>
            <link>https://medium.com/@lui.matthew/controlled-inputs-and-forms-in-react-a3f0a618d842?source=rss-f107b6484c5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3f0a618d842</guid>
            <category><![CDATA[coding-for-beginners]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[form-input]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Matthew Lui]]></dc:creator>
            <pubDate>Mon, 14 Nov 2022 12:01:16 GMT</pubDate>
            <atom:updated>2022-11-15T14:14:56.109Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently started learning React. One thing that stood out to me is how forms are handled differently with vanilla JavaScript and React.</p><p>Forms is something I struggled with when learning React. After practicing form inputs for several weeks, it gave me a better understanding on React forms.</p><p>Controlled inputs is away we can set up our form so that React can track the input values. For any e-commerce business, it’s very important we capture unique pieces of information a visitor of the site. This can be name, date of birth, email addresses which can be used for future marketing campaigns.</p><p>For example, if we set up input fields in forms, we can track their values. A user can type into the form and the value is tracked by state. If the state changes, that will update the value on the form.</p><p>Here is an example of how a controlled inputs help us track changes.</p><p>We will start with writing a simple function that will track the state of the form.</p><pre>function Form() {<br>const [name, setName] = useState(‘’)<br>}</pre><p>The beginning value is set to an empty string in State. This will also reflect in the text input field of our form.</p><p><strong>Name</strong> represents the current state of the form and <strong>setName </strong>is the setter function that we use to update the state of the form.</p><pre>&lt;input type=”text” required&gt; value={name}</pre><p>To track the changes on our form, react uses an onChange event listener to track the input values. As the user enters information, the value is constantly tracked by State.</p><pre>onChange={(e)=&gt; setName(e.target.value)</pre><p>I have include a simple block of code that tracks the a user’s name input.</p><pre>function Form() {<br>const [name, setName] = useState(‘’)<br>return (<br>&lt;div className= “form”&gt;<br>&lt;h1&gt;User Form&lt;/h1&gt;<br>&lt;label&gt;Name&lt;/label&gt;<br>&lt;input type=”text” required&gt; value={name}<br>onChange={(e)=&gt; setName(e.target.value)}&lt;/input&gt;<br>&lt;textarea required&gt;&lt;/textarea&gt;<br>&lt;button&gt;Add User&lt;/button&gt;<br>&lt;p&gt;&lt;/p&gt;<br>&lt;/div&gt;<br>);<br>}<br>export default Form;</pre><p>Also, quick tip if you would like to copy a code block onto medium, you can simply start the paragraph with 3 ```. Medium recognizes many programming languages.</p><p>To learn more about this topic, you can visit the <a href="https://reactjs.org/docs/forms.html">ReactJS official documentation</a> and <a href="https://www.w3schools.com/react/react_forms.asp">W3Schools</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3f0a618d842" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Event Listeners in Javascript]]></title>
            <link>https://medium.com/@lui.matthew/the-importance-of-event-listeners-4b7a53c5fdd8?source=rss-f107b6484c5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b7a53c5fdd8</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[js-eventlistener]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Matthew Lui]]></dc:creator>
            <pubDate>Wed, 05 Oct 2022 12:42:07 GMT</pubDate>
            <atom:updated>2022-11-22T14:18:59.521Z</atom:updated>
            <content:encoded><![CDATA[<p>Learning to code is something I wanted to do for a very long time. I am thankful that I finally have the opportunity fulfill my dream of becoming a software engineer.</p><p>Javascript is my first programming language. Learning the basics of this language was intimidating. I have made a lot of progress since the pre-work.</p><p>Prior to programming, I always wonder how our browsers were able to capture information about the user. Now I have a better understanding of how writing code can help triggers events that record information.</p><p>There are many types of events in Javascript</p><p>Here’s a list of a few events in Javascript as describe in <a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events">MDN</a></p><ul><li>The user selects, clicks, or hovers the cursor over a certain element.</li><li>The user chooses a key on the keyboard.</li><li>The user resizes or closes the browser window.</li><li>A web page finishes loading.</li><li>A form is submitted.</li><li>A video is played, paused, or ends.</li><li>An error occurs.</li></ul><p>There are two event listeners I’ve gotten a lot of exposure in my first Phase. The first one I will go over is a click event listener which can be attached to a HTML button element.</p><pre>const btn = document.querySelector(&#39;button&#39;);<br>function greet(event) {<br>console.log(&#39;greet:&#39;, event)<br>}<br>btn.addEventListener(&#39;click&#39;, greet);</pre><p>The click event is fired up when a user clicks on a button on a page that is attached to an event listener. The code above will greet a user once the button is clicked.</p><p>The second event is a submit event that is triggered when a user submits information to a webform.</p><pre><br>Const form = document.getElementById(&quot;user-form&#39;&quot;)<br>Form.addEventListener(&#39;submit&#39;, (event)=&gt;{<br>Event.preventDefault()<br>Const userInput = event.target[user-form].value</pre><p>The following code will capture the values the user inputs into the form.</p><p>You can learn more about event listeners at <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit_event">Mozilla</a> and <a href="https://www.w3schools.com/jsref/event_onsubmit.asp">W3Schools.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b7a53c5fdd8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>