Github Gist Is Here To Save The Day...Literally!

DISCLAIMER

Gist, a GitHub feature, can be used as a simple, basic database for small projects due to its create, read, update, delete (CRUD) functionalities accessible via GitHub’s API. However, it has limitations including a 1 MB size limit per gist, rate-limited API usage, lack of advanced database features, and limited data security and privacy. While it’s feasible, it’s typically not advised except for small, straightforward projects or prototypes. Larger projects should use a dedicated database system.
Welcome to the first tutorial on how to use Github Gist to save data for your roblox games! I’ve spent over 8+ hours trying to figure out a way to use github as a place that you can store your JSON and also edit it using the REST API, and I found out about Github Gist!

Github Gist is a place where you can share and collaborate code snippets and text or any other type of content, in our case we’re going to be using it to store our JSON for our game!

To start off, your going to have to head over to the official Github page and get your personal access token, you can do this by going to settings and scrolling all the way down until you see this

image

Click on Developer Settings, and then itll take you to this page where your going to want to click on Personal Access Tokens

After you clicked on that a drop down will show with two options, click the bottom option, Tokens (classic)

It should then bring up this where youll want to click Generate New Token, it’ll most likely ask you for your Github password so just give that and then it should generate a token for you, you can have it expire or not expire whenever you want but after the token is generated, make sure to scroll down and enable everything under the scopes!

It’s also a good idea to just save that token somewhere aswell, although if you forget it you can always just go through what I just told you again!

Now that we have our access token we can create our Gist!
So head over to https://gist.github.com/

You’ll be greeted with this nice menu, where you can put the gist description, file name + extension and the contents of the file!

You can set the gist description to anything you would like but for the filename and extension name it Data.json, although you dont have to it just makes it easier to remember what it’s for! For the content you can just put an empty dictionary

{}

And then press Create secret gist!
After this it will greet you with a new page, with your empty json file

Alright now we need to get the url for our Gist, so we can make requests to it!
It’s pretty simple, so it would go like

local Url = "https://api.github.com/gists/YOUR_GIST_ID" -- Replace with yours

So for the gist id, just look at the url and it would be this part
image

Now that you have the Url, we can setup the Headers which is where the token we created earlier will come into play, this basically tells the giist that your authorized too access it!

local accessToken = "YOUR_ACCESS_TOKEN"
local headers = {
   ["Authorization"] = "Bearer "..accessToken
}

I’m not really much of a web developer but the Bearer is just some token type that Gist uses to authorize you!

Now to simply retrieve our data we can simply do this

image

And this would yield this super long result of a bunch of information

image

But dont be afraid, we only need one part of this and it’s the content of our Data.json

So to access this we are going to want to decode the body we just recieved like so and then from the decoded body we can access the files which has our Data.json, and in our Data.json it has the content from our Data.json file!

It will print this out

image

Of course it is empty because we haven’t actually added anything inside of it yet, so that’s what were gonna do!

So there is alot of ways you may want to save data but I’m going to show you what I think is the best way and uses the PATCH method

Im this code were created a new variable that is housing the decoded data so that we can manipulate it too add a key to it if it doesnt exist, which in this case is Player1 and we set it to a table with some default values, think of this like what youd do when a player joins your game for the first time!

image


And we could add an else to this check so then we know if the player already has data, which in that case we can do something else

image


So going back to when the player doesnt have data yet, after we have **setup their data** we still need to add it to our Gist, so let's create another request. In this request we are creating a **new variable** that is going to be set to the **encoded version** of the data we just changed as we are going to be passing it to the **request** we are about to make, in the request in the Body we JSONEncode that and we tell it at which point we want to actually save the updated data too!


So after we run that, it will print this
image

And if we check our gist the changes are instantly updated!


And that’s really all for this tutorial, I really hope you guys start to use this because using JSON with httpservice is really slept on, any questions just feel free to drop them down below!

Also one more thing is that you can actually see the changes made to your data overtime, so thats pretty cool


Go make some great games!

13 Likes

this cool can be alternative of DataStore but am not sure too about duplication when player is hopping server and Too Many request error

2 Likes

Actually there a super easy way to detect that, in your data for that specific player just have some key called lastJoinTime and set it to something like tick() and when the player joins you can detect if its less than a certain number and kick them

I imagine this should be helpful to a handful of people, nonethless thank you for you r comment!

Data saving shouldnt be as hard as it is and players shouldnt have to worry about it ontop of making the entire game, I mean look at the creation of ProfileService and Datastore2; that kind of just proves it

1 Like

While this is a interesting solution to data storage

I do believe that this is against the policy of GitHub, however feel free to correct me if I am wrong.

6 Likes

Not sure what you’re talking about


@astraIboy Thank you for making this, I have been wanting to do this for a VERY long time!

My only request is for you to properly provide source code instead of screenshots, other than that this is really good!

Also would it be possible to store information in a different file format that’s not JSON for example Lua or any other type?

One more question, is it possible to create a new Gist entirely from within Roblox?

1 Like

That screenshot doesn’t appear to contain any actual information from GitHub themselves. Again, I am not certain if you can, just saying be careful and check for yourself in their policies.

2 Likes

While GitHub’s Terms of Service don’t expressly forbid using Gists as a makeshift database, they do have rules on fair use and limits on API requests to prevent misuse. Afaik, the rate limit is 5000 authenticated requests per hour. The terms also prohibit content that promotes illegal activities or creates liability. Misusing Gists in a way that disrupts GitHub’s service or involves illegal activity could be considered a terms violation. Although using Gists this way isn’t explicitly banned, it’s typically not the best solution and it’s recommended to review the current terms or reach out to GitHub with any specific usage concerns.

TL;DR You can use it without any problems, however not advisable for larger projects see why in “Potential Downsides”

Potential Downsides

Gist, a GitHub feature, can be used as a simple, basic database for small projects due to its create, read, update, delete (CRUD) functionalities accessible via GitHub’s API. However, it has limitations including a 1 MB size limit per gist, rate-limited API usage, lack of advanced database features, and limited data security and privacy. While it’s feasible, it’s typically not advised except for small, straightforward projects or prototypes. Larger projects should use a dedicated database system.

@astraIboy you should add a disclaimer, it would be unfortunate for an inexperienced developer to use this and to only find out that they have shot themselves in the foot

9 Likes

Please dont do this. This is a horrible idea for datastores. You are better off with roblox’s datastores instead. You are limited to 5000 authenticated requests per hour + 300 requests per minute. Dont do this if you want to make a big game. It also has a db limited to only ONE MEGABYTE OF STORAGE. its completely unacceptable for database usage. (Thats under the limit for key size for roblox datastores itself!)

7 Likes

The issue is that you are limited to 5000 authenticated requests per hour so don’t run on Github Gist for large experiences

pointed out by: @commitblue and @RuizuKun_Dev

Everything? I would advise only enabling the necessary scopes used by each token — in this case, only the gist scope — for security reasons. You would not want a malicious user to suddenly be able to perform undesirable actions through your GitHub account with a simple token.

2 Likes

Well none of that would happen if the person with the token wasnt dumb enough to leave it somewhere they shouldnt, but then again roblox datastores are just the way to go honestly, shouldve never posted this shit

Is this upgradable?

1 Like

wonderful approach to data security, that’s like having a post-it on a monitor with credentials to your bank account

probably nothing happens, but if it happens, you’ll lose a lot


You’re using it in a Roblox game. Perhaps a malicious plugin searches for keys in scripts and sends them to an attacker. Perhaps you hire staff and they (accidentally) share your code, or perhaps you uploaded your code to GitHub and forgot it was still on “public”.

Such accidents happen to everyone. It probably never happens, but if it does, an attacker has control over most of your account.

This is why tokens have their own permission sets. By using the PoLP principe (Principle of Least Privilege), you can easily prevent a lot of destruction by just clicking on a few boxes!

3 Likes

I could see this being used to store game-specific flags to toggle features on the fly for an experience with a small player-base — although there are probably much better ways to do this that wouldn’t break if your experience suddenly has a large influx or players.

Storing user-data is probably not a great idea though.

It isnt upgradable dont even think about trying to use it

1 Like

i wanna

ur just asking for pain at this point

i like to manually edit and have control of my data without using a 300 robux plugin

there are free alternatives like the free plugin versions

gimme them pls