DEV Community

Cover image for Drop all databases. Use this API for data storage.
Timo
Timo

Posted on

Drop all databases. Use this API for data storage.

For purely selfish needs, I created a self-hosted API for CRUD-ing json data with Go (called "emmer"). It's built for quick data storage, and integrates with any programming language. This article introduces this tool, and shows some examples.

API

In summary, the API is based on your JSON structure. So the example below is for CRUD-ing [key1][key2] in file.json. The value (which can be anything) is then added to the body of the request. Moreover, there are helper functions for appending and incrementing values.

DELETE/PUT/GET: /api/file/key1/key2/...
Enter fullscreen mode Exit fullscreen mode

Installation

You can install emmer with the command below. After that, you can run emmer to start. By default emmer will generate a username/password.

foo@bar:~$ go install github.com/TimoKats/emmer@latest
foo@bar:~$ emmer
2025/09/10 16:41:20 set username to: admin
2025/09/10 16:41:20 set password to: ************
2025/09/10 16:41:20 selected local fs in: /home/user/.emmer
2025/09/10 16:41:20 server is running on http://localhost:8080
Enter fullscreen mode Exit fullscreen mode

Example

In this example, we will use emmer to create a small database for blogs and comments. Note, username/password for (mandatory) basic auth is generated on startup, or set environment variables.

First, send a PUT request to /api/posts with the body shown below to create a json file.

{
  "post1": {"text": "Here I write my article"}
}
Enter fullscreen mode Exit fullscreen mode

Next, you can query this json file with GET requests. For example, sending a GET request to /api/posts/article1/text will return the text field of post1. Imagine using these custom endpoints to serve content on your website!

"Here I write my article"
Enter fullscreen mode Exit fullscreen mode

After storing the article, we want to add comments to our posts. This will be a list of "comment" objects. Emmer can handle this by adding the "append" parameter to our PUT request. For example, the comment below is sent to api/posts/post1/comments?mode=append.

{"comment": "great stuff", "username": "timo"}
Enter fullscreen mode Exit fullscreen mode

Finally, do a GET request to /api/posts/post1/comments to fetch all comments. Note, you can do the PUT request from step 3 again to keep adding comments to your article.

[
    {"comment": "great stuff", "username": "timo"},
    {"comment": "not great stuff", "username": "peter"}
    ...
]
Enter fullscreen mode Exit fullscreen mode

Finally, you can send DELETE requests to remove (parts of) your json file. Note, the final json file should look (something) like this. Depending on your selected filesystem (local, s3, etc) you can find this file and use/edit it with other programs.

{
    "post1": {
        "comments": [
            {"comment": "great stuff", "username": "timo"},
            {"comment": "not great stuff", "username": "peter"}
        ],
        "text": "Here I write my article"
    }
}
Enter fullscreen mode Exit fullscreen mode

If you're interested in this tool. Or if you want to contribute. Please visit GitHub.

Top comments (0)