<?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: Jemimah Kavyu</title>
    <description>The latest articles on DEV Community by Jemimah Kavyu (@mimahj).</description>
    <link>https://dev.to/mimahj</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%2F1002354%2Fee7173fb-28ff-42b5-9fb1-a3cea5752260.png</url>
      <title>DEV Community: Jemimah Kavyu</title>
      <link>https://dev.to/mimahj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mimahj"/>
    <language>en</language>
    <item>
      <title>Implementing an API fetch for your GitHub portfolio</title>
      <dc:creator>Jemimah Kavyu</dc:creator>
      <pubDate>Tue, 10 Jan 2023 19:50:38 +0000</pubDate>
      <link>https://dev.to/mimahj/implementing-an-api-fetch-for-your-github-portfolio-5ek5</link>
      <guid>https://dev.to/mimahj/implementing-an-api-fetch-for-your-github-portfolio-5ek5</guid>
      <description>&lt;p&gt;The Fetch API provides a javascript interface for accessing and manipulating parts of the protocol, such as requests and responses. It also provides a global fetch() method that provides an easy and logical way to fetch resources asynchronously across the network.&lt;/p&gt;

&lt;p&gt;In this project, we shall be implementing an API fetch for a GitHub portfolio, showing a page with a list of all the repositories on GitHub where the page should implement pagination for the repo list of repos using nested routes while using all the necessary tools in react.&lt;/p&gt;

&lt;p&gt;We shall also implement the proper SEO, Error boundary where we shall show a page to test the error boundary.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites.
&lt;/h3&gt;

&lt;p&gt;Install node js, npm, and git.&lt;/p&gt;

&lt;p&gt;Basic knowledge of HTML, CSS, JS and React.&lt;/p&gt;

&lt;p&gt;install create -react-app and create a new app my-app&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app my-app

cd my-app

npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Installation&lt;/p&gt;

&lt;p&gt;Fork the repos&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--THDrBMy0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qo13ybsml0fk3bs07cmk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--THDrBMy0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qo13ybsml0fk3bs07cmk.png" alt="Image description" width="880" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;open your terminal and clone the repository in your computer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/your_username/forked-repo-name.git"&gt;git clone&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aZ6QeCGK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x15fqlttclkqsi44vk1o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aZ6QeCGK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x15fqlttclkqsi44vk1o.png" alt="Image description" width="880" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Navigate into the cloned repo and install npm packages.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Update git remote&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/your_username/forked-repo-name.git"&gt;git remote set-url origin&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Start the live server&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This will show where your React app is hosted.&lt;/p&gt;

&lt;p&gt;Step 1&lt;br&gt;
Update the GitHub username.&lt;br&gt;
 -Change the GitHub username to your username. The website will update to your GitHub portfolio.&lt;/p&gt;

&lt;p&gt;Step 2&lt;br&gt;
Add code to fetch data from REST APIs.&lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/src"&gt;@src&lt;/a&gt;/components/LandingPage.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch(`https://api.github.com/users/${content.github_username}`)
.then(response =&amp;gt; response.json())
.then(result =&amp;gt; {
    this.setState({ user: result });
    document.title = `${result.name}'s Portfolio`;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;scroll down to componentDidMount() of the landing page class and copy paste the code above.&lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/src"&gt;@src&lt;/a&gt;/components/Projects.js&lt;br&gt;
Fetches user repositories&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch(`https://api.github.com/users/${github_username}/repos?${repo_endpoint_parameter}`)
.then(response =&amp;gt; response.json())
.then(result =&amp;gt; this.setState({ repos: result }));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Scroll down to componentDidMount of Projects class and copy paste the above code.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;



&lt;p&gt;&lt;code&gt;git commit -m "added code to fetch from github api"&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Step 3&lt;br&gt;
src/components/LandingPage.js&lt;br&gt;
Language Colors URL&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://raw.githubusercontent.com/Diastro/github-colors/master/github-colors.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Refference code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; /* We specify an endpoint to fetch data from. */
 fetch('http://example.com/movies.json')
 /*
 Once fetched, we then parse the response.

 Response will be in the form of a string,
 we convert the data to json via .json() method.
 */
 .then(function(response) {
    return response.json();
 })
 /*
 We can then do whatever we like with the json object.

 The example below converts the json back to a string and outputs to the console.
 */
 .then(function(myJson) {
    console.log(JSON.stringify(myJson));
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Scroll down to componentDidMount of LandingPage class and copy paste the above code.&lt;br&gt;
Once you fetch and parse the response as json, set the state of langColors to be the result of response.json(). i.e.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;this.setState({ langColors: result });&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Step 4&lt;br&gt;
Reconstruct TopBar src/components/LandingPage.js&lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/src"&gt;@src&lt;/a&gt;/components/LandingPage.js&lt;br&gt;
Image container&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;img src={user.avatar_url} className="br-100 pa1 ba b--black-10 h3 w3" alt="avatar" /&amp;gt;
&amp;lt;/ImageContainer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;UserInfo&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;span&amp;gt;{user.name}&amp;lt;/span&amp;gt;
    &amp;lt;span className="f6 font-ubuntu-mono"&amp;gt;&amp;amp;nbsp;@&amp;amp;nbsp;&amp;lt;/span&amp;gt;
    &amp;lt;span className="f6 font-ubuntu-mono"&amp;gt;{user.location}&amp;lt;/span&amp;gt;
    {/* Something was here, determine based on the above image. */}
&amp;lt;/UserInfo&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Languages&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;Languages&amp;gt;
    {topLang.slice(0, number_of_languages_to_show).map((lang, ind) =&amp;gt; (
        &amp;lt;Language key={ind} style={{color: `${langColors[lang[0]]}`}}&amp;gt;
            &amp;lt;Emoji src={emojis[ind]} /&amp;gt;
            {lang[0]}
        &amp;lt;/Language&amp;gt;
    ))}
&amp;lt;/Languages&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Social Media&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;SocialMedia&amp;gt;
    &amp;lt;GitHub urlToUse={`https://github.com/${github_username}`} /&amp;gt;
    {user.blog.includes("linkedin.com") &amp;amp;&amp;amp; &amp;lt;LinkedIn urlToUse={user.blog} /&amp;gt;}
    {user.blog.includes("twitter.com") &amp;amp;&amp;amp; &amp;lt;Twitter urlToUse={user.blog} /&amp;gt;}
    {user.blog.includes("hackerrank.com") &amp;amp;&amp;amp; &amp;lt;HackerRank urlToUse={user.blog} /&amp;gt;}
&amp;lt;/SocialMedia&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Scroll down to the render() method of the LandingPage component where you will find a commented session asking for help.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;



&lt;p&gt;&lt;code&gt;git commit -m "reconstructed TopBar&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Step 5&lt;br&gt;
Change logo icon background from square to circle&lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/src"&gt;@src&lt;/a&gt;/components/SocialMedia/Logo.js&lt;br&gt;
Go to the Logo component.&lt;br&gt;
Within its return statement, change the Square component to the Circle component.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git add&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;



&lt;p&gt;&lt;code&gt;git commit -m "changed logo from square to circle&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Step 6&lt;br&gt;
Deploying with netlify&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.netlify.com/"&gt;sign up at @&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Click on New Site from Git button and follow the instructions to set it up.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;3.&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;git push -u master&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;If you setup your Netlify to link to your GitHub repository you are pushing to, it should trigger Netlify to build and deploy based on the new pushed data.&lt;/p&gt;

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