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
Many here are saying GitHub Pages, but a simple GitHub repo is already enough.
Take this as example: raw.githubusercontent.com/microsof...
From any file in your repo just click the "Raw" button and there you have it. You can call a fetch on that URL :)
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 thecontent-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 togithack
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).Oh I didn't know that, thank you so much!
No doubt for me, a public github.com repo. Fully agree
Github Gist is also a free option, an even lighter option to a full repo. It also has the view raw option.
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
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 clickYes, I want to run scheduled CI in inactive repository
every ~90 days.Config for metrics, the Gist.
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 :)
If you're interested in metrics, I also found github.com/anmol098/waka-readme-stats and will try it some later.
GitHub pages maybe?
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!)
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)
never tried Github Pages so far, how would it be different from a Github repo or a simple gist?
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.
I see :)
Thanks!
I don't mind yes
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...
Thanks will check this out!
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
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-...
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.
You can use json-server. Check out this article for more information.
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.
gonna check this thanks
You can use the free tier of Render and serve your JSON using Node.js or any other environment they provide.
Did not know about Render, thank you!
Nextjs api get request returns static json file + Vercel hosting. Future proof and you can use your own domain!