<?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: JC</title>
    <description>The latest articles on DEV Community by JC (@jcbonassin).</description>
    <link>https://dev.to/jcbonassin</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%2F614637%2Fcdc4eaf0-d5c5-4059-b597-694b0a20074f.jpeg</url>
      <title>DEV Community: JC</title>
      <link>https://dev.to/jcbonassin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jcbonassin"/>
    <language>en</language>
    <item>
      <title>Part 2. Sharing data between siblings components using Context in React with Hooks</title>
      <dc:creator>JC</dc:creator>
      <pubDate>Mon, 31 Jan 2022 04:50:45 +0000</pubDate>
      <link>https://dev.to/jcbonassin/part-2-sharing-data-between-siblings-components-using-context-in-react-with-hooks-51d</link>
      <guid>https://dev.to/jcbonassin/part-2-sharing-data-between-siblings-components-using-context-in-react-with-hooks-51d</guid>
      <description>&lt;p&gt;Once we've got a context provider defined and in place it's time to make the data available on any child component. For this we will use a hook called useContext. &lt;/p&gt;

&lt;p&gt;"useContext accepts a context object and returns the current context value for that context. The current context value is determined by the value prop of the nearest above the calling component in the tree". What this means is this hook will give us access to the prop passing the context defined by the context function and wrap in the provider. Let's see it in the component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import React, { useContext } from "react";



function Profile()  {

    const pots = useContext(PostContext)
    const setPots = useContext(PostDispatchContext)



   return (
        &amp;lt;&amp;gt; 
   {posts.map(post =&amp;gt; &amp;lt;h2&amp;gt;{post}&amp;lt;/h2&amp;gt;)}
       &amp;lt;/&amp;gt; 

      );
}

export { Profile }


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

&lt;/div&gt;



&lt;p&gt;First we import useContext from the react library. Then we define our props calling the hook and passing the context created for the prop. In this case for posts we created PostContext to query the context state and PostDispatchContext to mutate the context state. This will give us access to the props state set as an empty array at first. &lt;/p&gt;

&lt;p&gt;And finally we can return the data we need. It's important to notice that setPosts is a function as de-structured. When using it to update posts it expects an object that we can easily iterate as a list of posts.  &lt;/p&gt;

&lt;p&gt;Context provides a way to pass data through the component tree from parent to child components, without having to pass props down manually at each level. It's specially useful to pass data deeply and great tool as a global state management.&lt;/p&gt;

&lt;p&gt;While React Context is native and simple to set, it isn’t a dedicated state management tool like Redux, however it can be really useful for prop drilling. &lt;/p&gt;

&lt;p&gt;Thanks for reading.. &lt;/p&gt;

</description>
      <category>react</category>
      <category>context</category>
      <category>javascript</category>
      <category>hooks</category>
    </item>
    <item>
      <title>Sharing data between siblings components using Context in React with Hooks</title>
      <dc:creator>JC</dc:creator>
      <pubDate>Mon, 31 Jan 2022 03:30:59 +0000</pubDate>
      <link>https://dev.to/jcbonassin/sharing-data-between-siblings-components-using-context-in-react-with-hooks-2b8i</link>
      <guid>https://dev.to/jcbonassin/sharing-data-between-siblings-components-using-context-in-react-with-hooks-2b8i</guid>
      <description>&lt;p&gt;Context in react was designed to share data or props in your app making this info available globally for a tree of components. In few words allows you to pass this info between any component without having to explicitly pass a prop through every level of the tree, like from parents to child for example. Before using Context is important to know that it's generally used when some data needs to be accessible by many components at different nesting levels. So how we use it?&lt;/p&gt;

&lt;p&gt;Let's say we need a prop called posts that needs to be available in few components of your app. The first thing will be to create a folder in your application called context which will contain your PostContext .jsx or .js file. Let's also say that we need to set the initial State of this prop as an empty array. So we can have something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { createContext, useState } from "react";


const PostContext = createContext(null);
const PostDispatchContext = createContext(null);

function PostProvider({ children }) {
    const [posts, setPosts] = useState([]);

    return (
      &amp;lt;PostContext.Provider value={posts}&amp;gt;
        &amp;lt;PostDispatchContext.Provider value={setPosts}&amp;gt;
          {children}
        &amp;lt;/PostDispatchContext.Provider&amp;gt;
      &amp;lt;/PostContext.Provider&amp;gt;
    );
  }

  export { PhotoProvider, PhotoContext, PhotoDispatchContext };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We import createContext &amp;amp; useState from the react library. This will allow us to create two const, first the Postcontext itself which allows to query the context state and the PostDispatchContext to mutate the context state. We can set that to null or undefined. &lt;/p&gt;

&lt;p&gt;Now we just need to create a function to define our provider and pass the children components that will use the data we are trying to share. It's important to mention that a "provider" is used to encapsulate only the components that needs the state in this context. we will see that later on. Finally we assign the state using the useState Hook and set an empty array as shown. Once this logic is defined we render the value of the context and wrap the values we need to expose later through the children components. It might sounds complicated but all we are doing here is to share the initial state of our prop and make it available through the provider. Once this is set It's time to export the provider PostProvider.&lt;/p&gt;

&lt;p&gt;Let's wrap the components that will use the posts and setPosts as Props.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function App() {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;PostProvider&amp;gt;
        &amp;lt;User /&amp;gt;
        &amp;lt;Comments /&amp;gt;
     &amp;lt;/PostProvider&amp;gt;
    &amp;lt;&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;Now posts is available globally in your app and useful for the components wrap with the provider. Due the nature of react context It is really important to make this props available on the components that really need them only. This is to avoid any performance drain in your app. Check the second part where I explain how to finally set the data for each components using useContext hook. &lt;/p&gt;

&lt;p&gt;Happy Coding &lt;/p&gt;

</description>
      <category>react</category>
      <category>context</category>
      <category>hooks</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Photo App on React and Ruby on Rails...</title>
      <dc:creator>JC</dc:creator>
      <pubDate>Sun, 30 Jan 2022 03:26:44 +0000</pubDate>
      <link>https://dev.to/jcbonassin/photo-app-on-react-and-ruby-on-rails-1coc</link>
      <guid>https://dev.to/jcbonassin/photo-app-on-react-and-ruby-on-rails-1coc</guid>
      <description>&lt;p&gt;The scope of this project was to implement React as front-end to my photo app Ruby of rails backend. So the app allows you to upload photos. &lt;/p&gt;

&lt;p&gt;Also you can create an account logging . Once you Sign in and create an account you will be able to add photos and delete them. This is all possible thanks to Ruby on Rails and React.&lt;/p&gt;

&lt;p&gt;An API was created to display the data. JWT was implemented to keep the data safe when created. &lt;/p&gt;

&lt;p&gt;React handles the Front-end and a user authentication was build with React/Redux to easily handle our JWT.&lt;/p&gt;

&lt;p&gt;Check it out and have a look at the code. It might be fun.&lt;/p&gt;

&lt;p&gt;What I learn:&lt;/p&gt;

&lt;p&gt;Complete and run a whole project in React and Ruby on rails.&lt;/p&gt;

&lt;p&gt;Integrate Redux to my react application and use it to handle a user JWT authentication.&lt;/p&gt;

&lt;p&gt;Create an app that serves as a community to add photos and share them.&lt;/p&gt;

&lt;p&gt;The implementation of useContext as a hook to help sharing data throughout different components in the app. &lt;/p&gt;

&lt;p&gt;The use of Hooks on functional components as well as managing states and props. &lt;/p&gt;

&lt;p&gt;Check the repo and have fun. Questions, concerns or issue can be manage though GitHub. &lt;/p&gt;

&lt;p&gt;You can find the Front-end here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/JcBonassin/35mmReact-front-end"&gt;35mm front-end&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and Backend here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/JcBonassin/35mm-react-backend-rails"&gt;35mm Backend&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please follow the instructions to install and ..Happy Coding &lt;/p&gt;

&lt;p&gt;Thanks for reading ..&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>ruby</category>
      <category>node</category>
    </item>
    <item>
      <title>Fun Ruby CLI project if you like Weather Stuff </title>
      <dc:creator>JC</dc:creator>
      <pubDate>Sun, 21 Nov 2021 15:41:56 +0000</pubDate>
      <link>https://dev.to/jcbonassin/fun-ruby-cli-project-if-you-like-weather-stuff-le5</link>
      <guid>https://dev.to/jcbonassin/fun-ruby-cli-project-if-you-like-weather-stuff-le5</guid>
      <description>&lt;p&gt;Weather Today in a Ruby CLI&lt;/p&gt;

&lt;p&gt;So I made my first gem Yay. It was challenging. It was hard. It took me a long time. &lt;/p&gt;

&lt;p&gt;I decided to build an app that took data from three different APIs. Why? Well I wanted to make it a bit challenging.&lt;/p&gt;

&lt;p&gt;This CLI was built to give a quick update of the weather either by your current location or any location you ask for. Also It  provides headlines of BBC news as a plus. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/JcBonassin/weather_today"&gt;Check it out&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So how do I build it? &lt;/p&gt;

&lt;p&gt;The first step was to identify the API's to use: &lt;br&gt;
so I signed for these awesome ones:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://openweathermap.org/"&gt;OPENWEATHERMAP&lt;/a&gt;. To get the good weather data.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://newsapi.org/"&gt;NEWSAPI&lt;/a&gt;. To get the news.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://app.abstractapi.com/"&gt;Abstract&lt;/a&gt;. To get a precise timeZone on the location enquiry. They've got a free plan too. So all cool. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So let's write the code: &lt;/p&gt;

&lt;p&gt;I  needed to get the data for the weather first so I built one Class for the IP location and one Class for a city search. I used  HTTParty to get the data and JSON to parse it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def self.api_location(unit)
response = HTTParty.get("https://api.openweathermap.org/data/2.5/weather?lat=#{lat}&amp;amp;lon=#{lon}&amp;amp;appid=#{ENV['API_KEY']}&amp;amp;units=#{unit}")
        data = JSON.parse(response.body, symbolize_names: true)
        @weather_today = self.new
        @weather_today.location = data[:name]
        @weather_today.time = Time.at(data[:dt])
        @weather_today.temp = data[:main][:temp].to_i
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;same for the search per city.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def self.select_name(units, location)
response = HTTParty.get("http://api.openweathermap.org/data/2.5/weather?q=#{location}&amp;amp;appid=#{ENV['API_KEY']}&amp;amp;units=#{units}")
      data = JSON.parse(response.body, symbolize_names: true)
      @weather_today = self.new
      @weather_today.response_code = data[:cod]
      if @weather_today.response_code === "404"
        spinner = TTY::Spinner.new("[:spinner] cod")
        spinner.error("404")
        return
      else
      @weather_today.location = data[:name]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once I located all data I needed for current weather and also forecast I started bulding my CLI. I wanted to get the following results: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check the current weather at current location and Forecast for the next 5 days &lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check the current weather and Forecast for the next 5 days at any city you name in the world plus a link to the city location on Google Maps. It only will work with city names. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It gives you 3 unit system to choose from: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Default (temperatures in Kelvin)&lt;/li&gt;
&lt;li&gt;Metric (temperatures in Celsius)&lt;/li&gt;
&lt;li&gt;Imperial (temperatures in Fahrenheit)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Read and open in your browser the latest world headlines from BBC News. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Gives you a funny quote according to weather conditions courtesy of the &lt;a href="https://github.com/reduxd/authentic-ubersicht"&gt;AUTHENTIC WEATHER APP&lt;/a&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Also a Big GoodBye. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;"Voila" you are ready to check the weather and news. &lt;/p&gt;

&lt;p&gt;Well not so Easy. I wanted to make it more user friendly so on my CLI I added a few TTY components that are really handy. &lt;br&gt;
Especially TTY-Prompt, TTY-Box &amp;amp; TTY-Tables. Want to check them all click &lt;a href="https://ttytoolkit.org/components/"&gt;Here&lt;/a&gt;. They are easy to implement and you can find plenty of documentation online. So give it a try if you like them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class WeatherToday::CLI

    $prompt = TTY::Prompt.new(active_color: :cyan)

    def call
        welcome
    end

    def welcome
        puts Rain.go 
        puts Intro.go 
        sleep (3)
        puts"
                                             .-. .-.  ,---.   ,-.     ,-.      .---.   
                                             | | | |  | .-'   | |     | |     / .-. )  
                                             | `-' |  | `-.   | |     | |     | | |(_) 
                                             | .-. |  | .-'   | |     | |     | | | |  
                                             | | |)|  |  `--. | `--.  | `--.  \ `-' /  
                                             /(  (_)  /( __.' |( __.' |( __.'  )---'   
                                            (__)     (__)     (_)     (_)     (_)     
    ".colorize(:cyan)
         units_selection
         puts ''
         puts "World's News"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All right. Once my CLI was running and the hard part of the project was done I decided to add some art ;). Well not exactly but something like a ASCII art. There are plenty of resources online so you won't get lost. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Qom74vdT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/72950188/113721208-ee3a2600-96b4-11eb-9ab2-9f564ec218f9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Qom74vdT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/72950188/113721208-ee3a2600-96b4-11eb-9ab2-9f564ec218f9.png" alt="Screenshot 2021-04-06 at 08 47 56" width="880" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well I know it is a lot but It was fun. What I learn: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API can be tricky and hard to work with but once you are in the Matrix It becomes easier. &lt;/li&gt;
&lt;li&gt;I need to improve my level of abstraction but for the first project I wasn't so bad I believe.&lt;/li&gt;
&lt;li&gt;There is so much you can do but overtime. It's hard to learn all at once. &lt;/li&gt;
&lt;li&gt;Finally it is cool to add something else you love ... like Art for example. It makes coding more enjoyable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading ..&lt;/p&gt;

&lt;p&gt;So long &lt;/p&gt;

</description>
      <category>cli</category>
      <category>weather</category>
      <category>ruby</category>
      <category>api</category>
    </item>
    <item>
      <title>Simple and Fun Sinatra Project</title>
      <dc:creator>JC</dc:creator>
      <pubDate>Sun, 21 Nov 2021 15:38:24 +0000</pubDate>
      <link>https://dev.to/jcbonassin/simple-and-fun-sinatra-project-41oe</link>
      <guid>https://dev.to/jcbonassin/simple-and-fun-sinatra-project-41oe</guid>
      <description>&lt;p&gt;My Weather BE  Sinatra Project&lt;/p&gt;

&lt;p&gt;As I like weather Stuff, my Sinatra project was an extension and improvement of my CLI Project. I kept working in refactoring the code and also adding some cool API's. &lt;/p&gt;

&lt;p&gt;The scope was to create a good user experience and great look. So the app allows you to check the weather at your location and find and update to any other location in the world. Also give you News of the day and a gallery of photos from the city you are connected. Once you Sign in and create an account you will be able to add different locations, modify and also delete them. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/JcBonassin/Weather_real"&gt;Check it out&lt;/a&gt; and have a look at the code. It might be fun.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u5s9BAi---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/72950188/122404437-d862a000-cf44-11eb-94fa-24f94010aaac.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u5s9BAi---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/72950188/122404437-d862a000-cf44-11eb-94fa-24f94010aaac.png" alt="Screenshot 2021-04-06 at 08 47 56" width="880" height="865"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What I learn: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;APIs are fun to work with and also a great source of interesting data. &lt;/li&gt;
&lt;li&gt;You can add some JS script if you dare to improve the user experience.&lt;/li&gt;
&lt;li&gt;Sinatra is simple to use and friendly. It was hard to find a lot of info online though. &lt;/li&gt;
&lt;li&gt;It is kind of cool to work out of your comfort zone and add new stuff like JS. It will help you for your future projects.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading ..&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>sinatra</category>
      <category>programming</category>
      <category>rails</category>
    </item>
    <item>
      <title>Easy Weather check on JavaScript and Rails as Backend. </title>
      <dc:creator>JC</dc:creator>
      <pubDate>Thu, 04 Nov 2021 21:42:06 +0000</pubDate>
      <link>https://dev.to/jcbonassin/easy-weather-check-on-javascript-and-rails-as-backend-mgk</link>
      <guid>https://dev.to/jcbonassin/easy-weather-check-on-javascript-and-rails-as-backend-mgk</guid>
      <description>&lt;p&gt;So I made my fourth app Yay. It was challenging. It was hard. It took me a long time. Basically I build my Backend on Ruby on Rails and the Frontend on JS. &lt;/p&gt;

&lt;p&gt;I decided to build an app that took data from the Open Weather map API. Why? Well I like weather stuff :)&lt;/p&gt;

&lt;p&gt;This app was built to give a quick update of the weather either by your current location or any location you ask for.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/JcBonassin/Easy-Weather-frontend" rel="noopener noreferrer"&gt;Check out the Frontend&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/JcBonassin/Easy_weather_api_backend" rel="noopener noreferrer"&gt;&amp;amp; Backend&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So how do I build it? &lt;/p&gt;

&lt;p&gt;The first step was to identify the API's to use: &lt;br&gt;
so I signed for this awesome one:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://openweathermap.org/" rel="noopener noreferrer"&gt;OPENWEATHERMAP&lt;/a&gt;. To get the good weather data.
So all cool. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So let's write the code: &lt;/p&gt;

&lt;p&gt;I  needed to get the data for the weather first so I built my backend on rails and fetch the weather. I used  rails to get the data and JSON to parse it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Location &amp;lt; ApplicationRecord
    belongs_to :user

    def self.search_location(location_query)
        results = Geocoder.search(location_query)
        if  results === []
            begin
              raise Error
              rescue Error =&amp;gt; e
                puts e.message
              end
              return
         end 
        response = results.first.coordinates  
        lat = response[0]
        lon = response[1]
        self.search(lat, lon)  
    end 

    def self.location_query(location_query)
        results = Geocoder.search(location_query)
        response = results[0]
    end


    def self.search(lat, lon)
        response = HTTParty.get("https://api.openweathermap.org/data/2.5/onecall?lat=#{lat}&amp;amp;lon=#{lon}&amp;amp;exclude=minutely&amp;amp;appid=#{ENV['API_KEY']}&amp;amp;units=metric")
        data = JSON.parse(response.body) 
    end 

   etc..............

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

&lt;/div&gt;



&lt;p&gt;Once I located all data I needed for current weather I started building my app. I wanted to get the following results: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check the current weather at any location&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Be able to give users the option to store a weather card on their accounts. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It will give the current temperature and conditions. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fetch all this data and building my Frontend application with JavaScrip. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To fetch the data a create a Class API and add some async functions for this goal like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Api {
    constructor() {
        this.baseURL = "http://localhost:7000/"
    }

    async fetchUsers() {
        let response = await fetch(this.baseURL + `/users`)
        let data = await response.json()
        return data
    }

    async postUser(email, password, registerUser) {
        let data = {
          user: {
            email,
            password
          }
        }


        let configObj = {
            method: "POST",
            headers: {
              "Content-Type": "application/json",
              Accept: "application/json"
            },
            body: JSON.stringify(data)
          }
          const fetchURL = registerUser ? `${this.baseURL}users` : `${this.baseURL}login`;

          fetch(fetchURL, configObj)
            .then(resp =&amp;gt; resp.json())
            .then(data =&amp;gt; { 
                if (data.errors) {
                email = '';
                password = '';
                alert(data.errors);
              } else {
                window.sessionStorage.currentUsername = data.user.username;
                window.sessionStorage.currentUserId = data.user.id;
                loginButton.remove();
                userLogin.remove();
                welcomeLoggin();
                allLocation(data.user.id);
                displayForm()  
            }
        });  
    }


    async createUser(username, email, password, registerUser) {
        let data = {
          user: {
            username,
            email,
            password
          }
        }
        console.log(data)

        let configObj = {
            method: "POST",
            headers: {
              "Content-Type": "application/json",
              Accept: "application/json"
            },
            body: JSON.stringify(data)
          }
          const fetchURL = registerUser ? `${this.baseURL}login` : `${this.baseURL}users`;

          fetch(fetchURL, configObj)
            .then(resp =&amp;gt; resp.json())
            .then(data =&amp;gt; { 
                if (data.errors) {
                username = '';
                email = '';
                password = '';
                alert(data.errors);
              } else {
                window.sessionStorage.currentUsername = data.user.username;
                window.sessionStorage.currentEmail = data.user.email;
                window.sessionStorage.currentUserId = data.user.id;
                loginButton.remove();
                userLogin.remove();
                welcomeLoggin();
                allLocation(data.user.id);
                displayForm()  
            }
        });  
    }


    async fetchURL() {
        const fetchURL = registerUser ? `${this.baseURL}users` : `${this.baseURL}login`;
        let response = await fetch(fetchURL)
        console.log(response)    
}

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

&lt;/div&gt;



&lt;p&gt;"yeah" you are ready to check the weather at any location. &lt;/p&gt;

&lt;p&gt;Well not so Easy. I wanted to make it more user friendly so added some extras for users on JS. So I created an User Class and a Basic Authentication connected to my backend on Rails...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Weather{
    constructor(){
        this.login = new Login()
    }
}

..........


async function validateLoginForm() {
        const loginemail = document.getElementById("logEmail").value;
        const loginpassword = document.getElementById("logPassword").value;

        if (loginemail == "" || loginpassword == "") {
            document.getElementById("errorMsg").innerHTML = "Please fill the required fields"
            return false;
        }

        else if (loginpassword.length &amp;lt; 2) {
            document.getElementById("errorMsg").innerHTML = "Your password must include atleast 8 characters"
            return false;
        }
        else {
            const data = await api.postUser(loginemail, loginpassword, false);
            // alert("Successfully logged in");
            return true;
        }
    }

.. Etc 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All right. Once my app was running and the hard part of the project was done I decided to add a face for each weather query... meaning a "Weather Card" ;)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72950188%2F140199010-5062b634-be2f-4a45-b0db-d55fe0da79f4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F72950188%2F140199010-5062b634-be2f-4a45-b0db-d55fe0da79f4.png" alt="Screenshot 2021-11-03 at 14 56 36"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well I know it is a lot but It was fun. What I learn: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;APIs can be tricky and hard to work with but once you are in the Matrix It becomes easier. &lt;/li&gt;
&lt;li&gt;JS could be really challenging fetching elements from and API. Using Classes simplify the job.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading ..&lt;/p&gt;

&lt;p&gt;So long &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>html</category>
      <category>rails</category>
    </item>
    <item>
      <title>35mm a Rails App for your pictures...</title>
      <dc:creator>JC</dc:creator>
      <pubDate>Mon, 20 Sep 2021 02:10:08 +0000</pubDate>
      <link>https://dev.to/jcbonassin/35mm-a-photo-sharing-app-37oj</link>
      <guid>https://dev.to/jcbonassin/35mm-a-photo-sharing-app-37oj</guid>
      <description>&lt;p&gt;As I like photo Stuff, my Ruby on Rails project was uploading photos and sharing through an application. I kept working in refactoring the code and also adding some cool stuff.&lt;/p&gt;

&lt;p&gt;The scope was to create a good user experience and great look. So the app allows you to upload photos, add tags like or not like them. Also you can create an account logging with your Facebook credential, cool right?? . Once you Sign in and create an account you will be able to add photos, modify and also delete them as well as check other users pictures and comment on them. This is all possible thanks to Ruby on Rails. &lt;/p&gt;

&lt;p&gt;Check it out and have a look at the code. It might be fun.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/JcBonassin/photo_35mm"&gt;35mm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What I learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Complete and run a whole project in Ruby on rails.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Integrate varius Gems like Device and Omniauth and Shrine to enhance the user experience of your app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create an app that serves as a community to add photos and share them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is kind of cool to work out of your comfort zone and add new stuff like JS. It will help you for your future projects.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading ..&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>app</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
