惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
月光博客
月光博客
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
Jina AI
Jina AI
小众软件
小众软件
U
Unit 42
云风的 BLOG
云风的 BLOG
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
宝玉的分享
宝玉的分享
B
Blog
C
Check Point Blog
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
量子位
阮一峰的网络日志
阮一峰的网络日志
Vercel News
Vercel News
酷 壳 – CoolShell
酷 壳 – CoolShell

Anže's Blog

The 15-Year-Old iptables Rule That Broke My DNS Fedidevs 9h Outage Postmortem Letting Claude Upgrade My Raspberry Pi Agents Day Lisbon DjangoCon Europe 2026 How to Safely Update Your Dependencies Speeding Up Django Startup Times with Lazy Imports Typing Your Django Project in 2026 Claude Fixes User Bug Jekyll to Hugo Migration Advent of Code 2025 🎄 Django bulk_update Memory Issue Migrating Gunicorn to Granian Disable Network Requests When Running Pytest Disable Runserver Warning in Django 5.2 Autogenerating og:images with Jekyll Power Outages and Gunicorn PID Files UV with Django Go-like Error Handling Makes No Sense in JavaScript or Python Packages Do Not Match the Hashes Pip Error Gotchas with SQLite in Production Fedidevs Dev Update #2 Django SQLite Production Config Django Streaming HTTP Responses Deploying a Django Project to My Raspberry Pi (Video) Thoughts on Code Reviews Django SQLite Benchmark Django, SQLite, and the Database Is Locked Error No Downtime Deployments with Gunicorn SQLite Write-Ahead Logging
The Fastest Way to Build a Read-only JSON API
Anže Pečar · 2023-01-16 · via Anže's Blog
16 Jan 2023

This is a short story on how I managed to not overengineer a read-only JSON API. TLDR: Sometimes a static .json file served by nginx is the easiest and fastest way to create a read-only JSON API endpoint.

The Problem

Last year I needed to build a simple JSON API endpoint for a mobile app that I was developing. The mobile app was a list view of webcams in my area. The final UI ended up looking like this:

Screenshot of the Surfcams app showing nested lists of surfcams available in my area

Since I wanted to be able to change the contents and the look and feel of the list without reinstalling the mobile application[1] I needed a JSON API to serve the data to be displayed.

JSON API

When I think about building a JSON API, I usually reach for Python with a framework like Django, Flask, or FastAPI. Python then connects to a database (PostgreSQL or SQLite most commonly) and responds to HTTP requests. But in this case, all of that seemed like overkill.

My API doesn’t have to change the response often. When it does need to change, I am the only one changing it. A database isn’t needed at all! ❌

I also don’t need dynamic routing that the above-mentioned frameworks provide. There is only one endpoint! I don’t really a web framework either! ❌

The response also doesn’t include any dynamic elements that would need to be computed on every request. I had to begrudgingly accept the fact that I don’t even need to use Python to solve this problem! ❌

A Static JSON file

So the whole endpoint ended up being a static cams.json file hosted on nginx. Since I already had nginx running on my Raspberry Pi where the project is hosted, I only needed to add the location /api/ path to my nginx site.conf:

    location /api/ {
        root /home/pi/projects/cams;
    }

After that I added the following cams.json file into the /home/pi/projects/cams folder:

{
    "categories": [
        {
            "title": "⭐️ Favorites",
            "color": "#ffd60a",
            "cams": [
                {
                    "title": "Carcavelos",
                    "subTitle": "Beachcam",
                    "url": "url1.m3u8",
                    "titleColor": "#ffffff",
                    "subTitleColor": "#999999",
                    "backgroundColor": "#363535"
                },
                {
                    "title": "Guincho",
                    "subTitle": "Beachcam",
                    "url": "url2.m3u8",
                    "titleColor": "#ffffff",
                    "subTitleColor": "#999999",
                    "backgroundColor": "#363535"
                },
                {
                    "title": "Costa de Caparica",
                    "subTitle": "Surfline",
                    "url": "url3.m3u8",
                    "titleColor": "#ffffff",
                    "subTitleColor": "#999999",
                    "backgroundColor": "#363535"
                }
            ]
         }
      ]
}

The real cam.json file is almost 1000 lines long, but you get the gist.

And that was it! Going to the /api/cams.json endpoint returns the JSON response so it looks and feels like a proper API endpoint. Nginx even correctly sets the content-type: application/json header.

The API endpoint has now been running for months and there were never any issues [2]. Fewer moving parts so fewer things go wrong.

Fin

As engineers, we often like to overengineer our solutions, especially when working on side projects. Do remember to strive for simplicity. Static files scale really well, even when they are serving JSON!


Footnotes

  1. I used Flutter for the mobile application, source code here.
  2. I did have a week of downtime that one time when my ISP changed my IP address while I was on vacation 😅. I was only able to get the new IP address once I returned home. I ended up solving this problem with some Golang code, but that’s a whole separate blog post.