DEV Community

Cyril Niobé
Cyril Niobé

Posted on

What is the best solution to host a simple JSON and fetch it for free?

I'd like to host a simple JSON (which I will probably change only 2 or 3 times a year manually) and have a fetch endpoint to retrieve it in my app.

What would be the best solution out there for this case without maintaining my own server?

Free options are even better

Top comments (27)

Collapse
 
balastrong profile image
Leonardo Montini

Many here are saying GitHub Pages, but a simple GitHub repo is already enough.

Take this as example: raw.githubusercontent.com/microsof...

Image description

From any file in your repo just click the "Raw" button and there you have it. You can call a fetch on that URL :)

Collapse
 
greglockwood profile image
Greg Lockwood

Not necessarily. The server at raw.githubusercontent.com is configured to always return file contents with two problematic response headers that make using it as a JSON file host not feasible.

The first header is content-type: text/plain; charset=utf-8 header, which means that if your means of fetching the JSON data requires it to have the content-type: application/json; charset=utf-8 header, which some do, then it will not work.

The second header is the more problematic, though. It is content-security-policy: default-src 'none'; style-src 'unsafe-inline'; sandbox. This prevents requests from outside the domain, which will be most of your requests.

However, there is a simple solution: just change githubusercontent in the URL to githack and it will work. A kind guy by the name of Pavel Puchkin runs it and it works great for dev projects. For production use, see raw.githack.com for the correct URL to use instead (and for other FAQs, etc).

Collapse
 
balastrong profile image
Leonardo Montini

Oh I didn't know that, thank you so much!

Collapse
 
cavo789 profile image
Christophe Avonture

No doubt for me, a public github.com repo. Fully agree

Collapse
 
izzlenizzle profile image
Isaac P

Github Gist is also a free option, an even lighter option to a full repo. It also has the view raw option.

Collapse
 
cyril profile image
Cyril Niobé

Indeed, I already tried the gist option (no fetching but editing) it once a day with the POST api. And Github did not appreciate that, I got a warning message from their team to tell me it's not the appropriate use case for gist and so they deactivated it ahah.

But for getting the raw url should be totally ok you're right :D

Thread Thread
 
perchun profile image
Perchun Pak

Strange, I use github.com/lowlighter/metrics (tl;dr a bunch of metrics that is updated through GitHub Actions, and just push rendered content to .svg file few times a day) with push to gist option. I had no messages from the GitHub staff. Furthermore, I only need to click Yes, I want to run scheduled CI in inactive repository every ~90 days.

Config for metrics, the Gist.

Thread Thread
 
cyril profile image
Cyril Niobé

oh good to know!

I guess it's "ok" while using github actions. I used a cron iob in the cloud which use the POST endpoint API to push a json updated every 12 hours on gist and the Github team detected it and ask me to remove it ahah.

I did not know about metrics, looks reaaaally cool! Will try it :)

Thread Thread
 
perchun profile image
Perchun Pak

If you're interested in metrics, I also found github.com/anmol098/waka-readme-stats and will try it some later.

Collapse
 
ben profile image
Ben Halpern

GitHub pages maybe?

Collapse
 
cyril profile image
Cyril Niobé

I should have mentioned that I tried the gist option (no fetching but editing) it once a day with the POST api. And Github did not appreciate that, I got a warning message from their team to tell me it's not the appropriate use case for gist and so they deactivated it ahah.

How Github pages would be different? (honest question!)

Collapse
 
andrewbrown profile image
Andrew Brown 🇨🇦

Github Pages, I don't think it would ever cost anything

All cloud service providers have Object Storage with static website hosting, and its practically free (I say this since it really depends on if you have insane insanve volume)

Collapse
 
cyril profile image
Cyril Niobé

never tried Github Pages so far, how would it be different from a Github repo or a simple gist?

Collapse
 
andrewbrown profile image
Andrew Brown 🇨🇦

I mean you could do that as well if you source the raw file.

I think its just more normal to go with Github Pages since your intended use is to treat it as static website assets serve over a CDN so you will be able to apply your custom domain, get a nice clean URL and using it as intended.

Thread Thread
 
cyril profile image
Cyril Niobé

I see :)
Thanks!

Collapse
 
cyril profile image
Cyril Niobé

I don't mind yes

Collapse
 
rickdelpo1 profile image
Rick Delpo • Edited

I wrote a Dev article on how to host a JSON file in an AWS S3 bucket. Also there is a free frontend plain javascript example of how to fetch the data. I use javascript array methods to manipulate the data via an AWS Lambda function which costs me only 5 cents per month after a 12 month free trial

click here for more
dev.to/rickdelpo1/to-sql-or-to-nos...

Collapse
 
cyril profile image
Cyril Niobé

Thanks will check this out!

Collapse
 
rickdelpo1 profile image
Rick Delpo

Please feel free to contact me if u get stuck on anything. At first AWS can be somewhat intimidating but I guarantee that what I am proposing is a very simple solution once u get the hang of dealing with some aws quirks. At minimum u can store ur json in s3 and just access it from the bucket object URL without needing to do an AWS Lambda function. I wrote a separate piece on how to render data directly from s3.

Good Luck and don't give up on AWS

Collapse
 
jaironlanda profile image
Jairon Landa

For anyone looking for JSON hosting, you can check here. We offer powerful features such as unlimited requests and up to 5MB of storage. Check out my post here for more details.

dev.to/jaironlanda/host-your-json-...

Collapse
 
dot_louis profile image
Louis

Hey Cyril, I usually go with Netlify's simplicity. Drag and drop a folder with an index.html (empty file will do) and the json file and you're good to go.
Image description

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

You can use json-server. Check out this article for more information.

Collapse
 
andrewbaisden profile image
Andrew Baisden

I have an article on deployment which will help you.

How to deploy your web applications online - snappify

In this article, we will learn about 5 FREE Heroku alternatives and how to deploy the front-end for your JavaScript applications to these platforms.

favicon snappify.com
Collapse
 
cyril profile image
Cyril Niobé

gonna check this thanks

Collapse
 
carlosds profile image
Karel De Smet

You can use the free tier of Render and serve your JSON using Node.js or any other environment they provide.

Collapse
 
cyril profile image
Cyril Niobé

Did not know about Render, thank you!