<?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: Darrian Bagley</title>
    <description>The latest articles on DEV Community by Darrian Bagley (@darrian).</description>
    <link>https://dev.to/darrian</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%2F845417%2F934c1f69-8da3-4a85-8426-01cc04968cc1.png</url>
      <title>DEV Community: Darrian Bagley</title>
      <link>https://dev.to/darrian</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/darrian"/>
    <language>en</language>
    <item>
      <title>Simultaneous “has_many” and “has_many :through” Associations using Rails ActiveRecord</title>
      <dc:creator>Darrian Bagley</dc:creator>
      <pubDate>Sat, 06 Aug 2022 07:24:00 +0000</pubDate>
      <link>https://dev.to/darrian/simultaneous-hasmany-and-hasmany-through-associations-using-rails-activerecord-3p17</link>
      <guid>https://dev.to/darrian/simultaneous-hasmany-and-hasmany-through-associations-using-rails-activerecord-3p17</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;We can connect two tables using multiple associations simultaneously. For example: &lt;code&gt;User has_many: :tasks&lt;/code&gt; and &lt;code&gt;User has_many: :tasks, through: :projects&lt;/code&gt;. There are a lot of potential uses for this method. I'll be using an example task management application in which Users have a direct connection to Tasks they create and an indirect association to Tasks that are in Projects that have been shared with them by other Users.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  TL;DR Solution
&lt;/h2&gt;

&lt;p&gt;To establish multiple associations between two tables, use a different name for the attribute and use the &lt;code&gt;source&lt;/code&gt; property to define the table being connected. We can use &lt;code&gt;has_many, :through&lt;/code&gt; to define an indirect association and &lt;code&gt;has_many&lt;/code&gt; to create a direct association.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  has_many :tasks`
  has_many :project_tasks, through: :projects, source: :tasks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, I recommend creating a model method to access all of a User’s Tasks. Keep in mind that the two collections may overlap, so we’ll use the &lt;code&gt;uniq&lt;/code&gt; method to remove duplicates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  def all_qr_codes
    (self.qr_codes + self.shared_qr_codes).uniq
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: In my examples, I’m using Rails 7.0.3.1. Other versions may not support this syntax, but the principles still apply.&lt;/p&gt;

&lt;h2&gt;
  
  
  Explanation
&lt;/h2&gt;

&lt;p&gt;That’s the short answer, now into the details. Let’s create relationships between three models in a hypothetical task management application.&lt;/p&gt;

&lt;p&gt;Here’s our end goal:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Users will be able to create Tasks and Projects.&lt;/li&gt;
&lt;li&gt;Users will be able to add Tasks to Projects.&lt;/li&gt;
&lt;li&gt;Users will be able to add other Users to Projects.
The tricky part:&lt;/li&gt;
&lt;li&gt;Not every task will be part of a project, so Users need a direct association with Tasks.&lt;/li&gt;
&lt;li&gt;Users won’t have a direct association with Tasks that are related to Projects that have been shared by other Users. This will require an indirect &lt;code&gt;has_many :through&lt;/code&gt; association.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We want to give Users a &lt;code&gt;has_many&lt;/code&gt; relationship with Tasks, a &lt;code&gt;has_many&lt;/code&gt; relationship with Projects, and a &lt;code&gt;has_many :through&lt;/code&gt; relationship connecting Users to Tasks through Projects. However, if you try to add both to the User model using the name &lt;code&gt;:tasks&lt;/code&gt; for both associations, Rails won’t be able to process the migration. That’s why using a different name for the &lt;code&gt;has_many :through&lt;/code&gt; relationship works.&lt;/p&gt;

&lt;p&gt;Next up, I’ll walk you through creating this schema from start to finish. These instructions assume you’ve already created a Rails project and have a basic understanding of Ruby on Rails.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Creating the Tables and Models
&lt;/h2&gt;

&lt;p&gt;We’ll create basic models for Users, and Projects, Tasks. I recommend using Rails generators if you know how to, but here’s what the corresponding database migrations should look like (with bare minimum fields). We’ll start with the migrations to create tables for the models:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateUsers &amp;lt; ActiveRecord::Migration[7.0]
  def change
    create_table :users do |t|
      t.string :username
      t.timestamps
    end
  end
end

class CreateTasks &amp;lt; ActiveRecord::Migration[7.0]
  def change
    create_table :tasks do |t|
      t.string :title
      t.belongs_to :user
      t.belongs_to :project, optional: true
      t.timestamps
    end
  end
end

class CreateProjects &amp;lt; ActiveRecord::Migration[7.0]
  def change
    create_table :projects do |t|
      t.string :title
      t.timestamps
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Many-to-Many: Projects and Users via Join Table
&lt;/h2&gt;

&lt;p&gt;To create our many-to-many relationship between Users and Projects, we can use a join table. You can run:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails generate migration CreateProjectsUsersJoinTable projects users&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;The resulting migration creates a table called projects_users. Each record will store 2 foreign keys defining a connection between a user and a project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateProjectsUsers &amp;lt; ActiveRecord::Migration[7.0]
  def change
    create_table :projects_users do |t|
      t.references :user, foreign_key: true
      t.references :project, foreign_key: true
      t.timestamps
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need to add these lines to the models (pay attention to the order of associations, we have to connect to &lt;code&gt;projects_users&lt;/code&gt; before we connect to &lt;code&gt;projects&lt;/code&gt; through 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 User &amp;lt; ActiveRecord::Base
  has_many :projects_users
  has_many :projects, through: :projects_users
end

class Project &amp;lt; ActiveRecord::Base
  has_many :projects_users
  has_many :users, through: :projects_users
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: One-To-Many: Users and Tasks Direct Association
&lt;/h2&gt;

&lt;p&gt;Let’s add &lt;code&gt;has_many :tasks&lt;/code&gt; to the User model and the Project model. Be sure you’ve added the &lt;code&gt;t.belongs_to :user&lt;/code&gt; and &lt;code&gt;t.belongs_to :project&lt;/code&gt; columns to the Tasks table which will store the foreign keys. Then we can add these lines to the models:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User &amp;lt; ActiveRecord::Base
  has_many :projects_users
  has_many :projects, through: :projects_users
  has_many :tasks
end

class Project &amp;lt; ActiveRecord::Base
  has_many :projects_users
  has_many :users, through: :projects_users
  has_many :tasks
end

class Task &amp;lt; ActiveRecord::Base
  belongs_to :user
  belongs_to :project
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: One-To-Many: Users and Tasks Indirect Association through Projects
&lt;/h2&gt;

&lt;p&gt;Finally, to create the &lt;code&gt;has_many :through&lt;/code&gt; relationship between Users and Tasks through Projects, we’ll add this line to the User model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User &amp;lt; ApplicationRecord
  has_many :projects_users
  has_many :projects, through: :projects_users
  has_many :tasks
  has_many :project_tasks, through: :projects, source: :tasks
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, as I mentioned before, we can create a model method to query all of a User’s Tasks. Keep in mind that the two collections may overlap, so we’ll use the &lt;code&gt;uniq&lt;/code&gt; method to remove duplicates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  def all_qr_codes
    (self.qr_codes + self.shared_qr_codes).uniq
  end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What is a Direct Association?
&lt;/h2&gt;

&lt;p&gt;A direct association is when a record has a column containing the ID of another record it has a relationship with. This is usually the case for one-to-many relationships where the child model has a column containing the ID of the parent model. Here’s an example of a one-to-many direct relationship in 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 Author &amp;lt; ApplicationRecord
  has_many :books
end

class Book &amp;lt; ApplicationRecord
  belongs_to :author
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What is an Indirect Association?
&lt;/h2&gt;

&lt;p&gt;Indirect associations are used to define a relationship between two records through a mutual record they’re connected to. This is often used to create join tables. In the following example, Physicians and Patients are connected through mutual appointments. Appointments have a one-to-many direct association with Physicians and Patients. By using “through:” a many-to-many indirect relationship is created between Physicians and Patients who share an appointment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Physician &amp;lt; ApplicationRecord
  has_many :appointments
  has_many :patients, through: :appointments
end

class Appointment &amp;lt; ApplicationRecord
  belongs_to :physician
  belongs_to :patient
end

class Patient &amp;lt; ApplicationRecord
  has_many :appointments
  has_many :physicians, through: :appointments
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that’s it! Hopefully this explanation has helped you configure your Rails database and clarified how &lt;code&gt;has_many&lt;/code&gt; and &lt;code&gt;has_many :through&lt;/code&gt; can be used to create direct and indirect associations. If you know a better solution to connect Users to Tasks through projects and directly, leave a comment and let me know!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Ruby Methods to Increase your Programming Efficiency</title>
      <dc:creator>Darrian Bagley</dc:creator>
      <pubDate>Tue, 05 Jul 2022 22:06:18 +0000</pubDate>
      <link>https://dev.to/darrian/ruby-methods-to-increase-your-programming-efficiency-13mi</link>
      <guid>https://dev.to/darrian/ruby-methods-to-increase-your-programming-efficiency-13mi</guid>
      <description>&lt;p&gt;Using the right Ruby methods can save you a lot of work. The more methods you are familiar with the faster you can produce working code &amp;amp; the better this code will be, both in performance &amp;amp; quality. To improve your productivity, here are some helpful methods that you may not have seen before.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prefix &amp;amp; Suffix Methods
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;start_with?&lt;/code&gt; &amp;amp; &lt;code&gt;end_with?&lt;/code&gt; return boolean results based on whether the beginning or end of a string match the provided string.&lt;br&gt;
&lt;code&gt;delete_suffix&lt;/code&gt; and &lt;code&gt;delete_prefix&lt;/code&gt; remove from the beginning or end of a string if the suffix or prefix match the provided string.&lt;/p&gt;
&lt;h3&gt;
  
  
  Percent String Literals
&lt;/h3&gt;

&lt;p&gt;Besides %(...) which creates a String, the % may create other types of object. As with strings, an uppercase letter allows interpolation and escaped characters while a lowercase letter disables them. For the two array forms of percent string, if you wish to include a space in one of the array entries you must escape it with a “\” character.&lt;br&gt;
These are the types of percent strings in ruby:&lt;br&gt;
&lt;code&gt;%i&lt;/code&gt; - Array of Symbols&lt;br&gt;
&lt;code&gt;%q&lt;/code&gt; - String&lt;br&gt;
&lt;code&gt;%r&lt;/code&gt; - Regular Expression&lt;br&gt;
&lt;code&gt;%s&lt;/code&gt; - Symbol&lt;br&gt;
&lt;code&gt;%w&lt;/code&gt; - Array of Strings&lt;br&gt;
&lt;code&gt;%x&lt;/code&gt; - Backtick (capture subshell result)&lt;/p&gt;
&lt;h3&gt;
  
  
  Convert Number to an Array of Digits
&lt;/h3&gt;

&lt;p&gt;the &lt;code&gt;digits&lt;/code&gt; method returns an array of a number's digits in reverse.&lt;br&gt;
&lt;code&gt;123.digits =&amp;gt; [3, 2, 1]&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  The Object Tap Method
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;tap&lt;/code&gt; method allows you to perform an action on an object then return the object.&lt;br&gt;
Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user = User.new
user.name = "John"
user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.new.tap { |user| user.name = "John" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The new object will be returned after performing the operation which avoids using a temporary variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Transforming Multiple Hash Values
&lt;/h3&gt;

&lt;p&gt;When you need to transform all of the values in a hash, say doubling your inventory, you can use the &lt;code&gt;transform_values&lt;/code&gt; method.&lt;br&gt;
Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;inventory = {item_A: 200, item_B: 300}
inventory.each { |k,v| h[k] = v*2 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;inventory = {item_A: 200, item_B: 300}
inventory.transform_values! { |v| v * 2 }
{:item_A=&amp;gt;400, :item_B=&amp;gt;600}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ruby</category>
    </item>
    <item>
      <title>Protecting Private API Keys using a Simple Proxy Server</title>
      <dc:creator>Darrian Bagley</dc:creator>
      <pubDate>Sat, 28 May 2022 22:03:02 +0000</pubDate>
      <link>https://dev.to/darrian/protecting-private-api-keys-using-a-simple-proxy-server-45cc</link>
      <guid>https://dev.to/darrian/protecting-private-api-keys-using-a-simple-proxy-server-45cc</guid>
      <description>&lt;p&gt;Two common mistakes developers make when using a private API key in their application are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Including the API key in the source code&lt;/li&gt;
&lt;li&gt;Including the API key in client-side HTTP requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Revealing private API keys and authorization tokens to users through client-side HTTP requests and in your source code exposes you and your application to a high risk of abuse. If a malicious user uses your API key for their application, it can cost you money and potentially prevent you from using the API by exceeding your usage limits.&lt;/p&gt;

&lt;p&gt;To avoid this, it’s recommended that you perform any requests that require authentication from the back-end of your application (a server) rather than the browser. However, if you need to make requests on the fly on the client-side, a quick way to accomplish this more securely is to use a proxy server to wrap requests with the necessary headers/query parameters containing your keys.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Proxy Server?
&lt;/h2&gt;

&lt;p&gt;A proxy server acts as a middle-man between your application and the API. There are 3 steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You send a request to the server.&lt;/li&gt;
&lt;li&gt;The server sends that request to the API.&lt;/li&gt;
&lt;li&gt;The server responds to your request with the response from the API.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The proxy server I’m going to demonstrate here is only slightly more secure than using your keys in the browser as, without further precautions (such as domain restrictions), other users could simply make requests through your proxy. I’ll explain further precautions you can take at the end of this post.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Proxy Server Example
&lt;/h2&gt;

&lt;p&gt;Here’s an example proxy server I wrote using Deno. I used Deno for because Deno Deploy is offering free hosting while it's in public beta (as of May 2022). If you visit &lt;a href="https://deno.com/deploy"&gt;Deno Deploy&lt;/a&gt; and start a playground project, you can try this out for yourself using this code!&lt;/p&gt;

&lt;p&gt;If you're using Node, the same principles apply, but you'll have to rewrite the code to use Express or another Node-based web application framework.&lt;/p&gt;

&lt;p&gt;This server makes requests to the Twitter API. To authenticate my requests, I must include an “Authorization” header with a bearer token as its value. I'll send requests to the proxy server and it will attach the Authorization header and send the request to the API.&lt;/p&gt;

&lt;p&gt;To make my requests through the proxy, I’ll replace the API domain with my server's domain.&lt;/p&gt;

&lt;p&gt;Here's an example: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My server is hosted at &lt;code&gt;https://my-project.deno.dev&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;I want to send a request to the Twitter API at &lt;code&gt;https://api.twitter.com/2/tweets?ids=1261326399320715264&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To send the request via my proxy server from my application, I would use this combined URL: &lt;code&gt;https://my-project.deno.dev/2/tweets?ids=1261326399320715264&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { serve } from "https://deno.land/std@0.137.0/http/server.ts";

const bearer = "Bearer MYBEARERTOKEN";

async function handler(req) {
  const url = new URL(req.url);
  const pathname = url.pathname;

  // Replace server domain with Twitter API domain for the proxy request
  const fetchURL = `https://api.twitter.com${pathname}${url.search}`;

  // Only make proxy request if there is a URL path
  if (pathname.length &amp;gt; 1) {
    const res = await fetch(fetchURL, {
      headers: { Authorization: bearer }
    });

    // If there is a response body, send it as text to the application.
    if (res.body) {
      return new Response(await res.text(), {
        headers: { "Access-Control-Allow-Origin": "*" }
      });
    }
  }
  // If there is no URL path, display "Hello World"
  return new Response("Hello World");
}

serve(handler);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Further Precautions
&lt;/h2&gt;

&lt;p&gt;As I mentioned earlier, this simple proxy server will prevent users from seeing your private API keys in your source code and HTTP requests, but a user might still make requests using your proxy server.&lt;/p&gt;

&lt;p&gt;A precaution you can take to prevent this is to restrict requests from other domains. Simply change the Response header "Access-Control-Allow-Origin" from "*" to the hostname you want to accept requests from. Example: &lt;code&gt;{ "Access-Control-Allow-Origin": "https://www.google.com" }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And that's it! If you have any thoughts on this method of protecting API credentials or other precautions you recommend, please mention them in the comments below!&lt;/p&gt;

</description>
      <category>server</category>
      <category>deno</category>
      <category>javascript</category>
      <category>api</category>
    </item>
    <item>
      <title>Creating a Free Static API using a GitHub Repository</title>
      <dc:creator>Darrian Bagley</dc:creator>
      <pubDate>Mon, 25 Apr 2022 02:04:11 +0000</pubDate>
      <link>https://dev.to/darrian/creating-a-free-static-api-using-a-github-repository-4lf2</link>
      <guid>https://dev.to/darrian/creating-a-free-static-api-using-a-github-repository-4lf2</guid>
      <description>&lt;p&gt;Most APIs on the web are dynamic, meaning they're capable of generating, updating, and transforming content in response to requests. A static API is simply a collection of files (typically JSON) that are hosted online and can be accessed via HTTP request by an application. Unlike a dynamic API, a static API is unable to perform actions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use a Static API
&lt;/h2&gt;

&lt;p&gt;Because dynamic APIs require you to run an application on a server, they can be expensive and difficult to maintain (especially at scale). Sometimes your application needs to access data via HTTP requests but doesn't need the other functionality an API can provide. If that's you, a static API can save you time and money, especially if you make use of a free static hosting solution, like GitHub.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use a Static API
&lt;/h2&gt;

&lt;p&gt;Consider using a static API if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You don't need to authenticate requests&lt;/li&gt;
&lt;li&gt;You only need to deliver pre-made content&lt;/li&gt;
&lt;li&gt;Actions don't need to be triggered by requests&lt;/li&gt;
&lt;li&gt;The content is not updated frequently&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to use GitHub to Create Your Static API
&lt;/h2&gt;

&lt;p&gt;To create a static API, all you need is to host JSON files somewhere online. Here's how you can do so for free using a GitHub repository:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Create your JSON files.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Create a JSON file containing the data you want each request to return. Name the files descriptively so you know what you're requesting in your code.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Create a public GitHub repository.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you've never used GitHub, you'll need to create a free account. Here's the &lt;a href="https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-new-repository"&gt;documentation on how to create a repository&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Upload your JSON files to the repository.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Here's &lt;a href="https://docs.github.com/en/repositories/working-with-files/managing-files/adding-a-file-to-a-repository"&gt;documentation on how to upload files&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;Access your files via URL.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The easiest way to do this is using GitHub RAW file URLs, HOWEVER, this is not best practice. In your final application, it's highly recommended that you use &lt;strong&gt;GitHub Pages&lt;/strong&gt;, which will serve your files via CDN for better performance. I'll explain both methods.&lt;/p&gt;

&lt;h4&gt;
  
  
  Method 1: GitHub Pages (Recommended)
&lt;/h4&gt;

&lt;p&gt;GitHub Pages is GitHub's free static hosting solution. Follow their &lt;a href="https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-github-pages-site"&gt;documentation on how to enable GitHub Pages in your repository&lt;/a&gt;. Don't worry about giving your website a theme as the appearance of the site won't matter.&lt;/p&gt;

&lt;p&gt;Once you've set up GitHub Pages in your repository, access your JSON files using this URL pattern: https://.github.io///&lt;/p&gt;

&lt;h4&gt;
  
  
  Method 2: GitHub RAW File URLs
&lt;/h4&gt;

&lt;p&gt;This method doesn't require any additional setup. The URL to your raw file will look like this:&lt;br&gt;
&lt;a href="https://raw.githubusercontent.com/"&gt;https://raw.githubusercontent.com/&lt;/a&gt;////&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example&lt;/em&gt;: &lt;a href="https://raw.githubusercontent.com/github/platform-samples/master/LICENSE.txt"&gt;https://raw.githubusercontent.com/github/platform-samples/master/LICENSE.txt&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, the user "github" has a repository named "platform-samples" with a branch named "master" that contains the file "LICENSE.txt" in the root directory.&lt;/p&gt;

&lt;p&gt;If the file is in a folder in the repository, rather than the root directory, remember to include the path in the URL. &lt;em&gt;Example&lt;/em&gt;: &lt;a href="https://raw.githubusercontent.com/github/platform-samples/master/sql/metrics/actions-summary.sql"&gt;https://raw.githubusercontent.com/github/platform-samples/master/sql/metrics/actions-summary.sql&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Notes
&lt;/h2&gt;

&lt;p&gt;You can use GitHub raw file links to access files from any public GitHub repository, not just your own. If someone else has made data available for public use, this can be a great way to access it if they haven't made it available via an API (or if their API doesn't suit your needs).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HOWEVER&lt;/strong&gt; The owner of the repository could modify or remove their files at any point. To avoid changes breaking your application, &lt;a href="https://docs.github.com/en/github-ae@latest/get-started/quickstart/fork-a-repo"&gt;fork the repository&lt;/a&gt; and fetch the data from your fork instead.&lt;/p&gt;

</description>
      <category>github</category>
      <category>json</category>
      <category>api</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
