Sign inSign up

banghasan/serverjson

By banghasan

•Updated 11 months ago

A simple web service built with Deno and Hono for handling CRUD operations on JSON data.

Image
API management
Developer tools
Web servers
0

709

banghasan/serverjson repository overview

⁠JSON CRUD SERVER

A simple web service built with Deno and Hono for handling CRUD operations on JSON data.

⁠Features

  • Full CRUD operations (Create, Read, Update, Delete)
  • Individual JSON files stored in data directory
  • Authentication required for write operations
  • YAML-based configuration
  • Automatic cleanup of old files
  • CORS support

⁠Docker Compose:

services:
  serverjson:
    image: banghasan/serverjson:main
    container_name: serverjson
    ports:
      - "8000:8000"
    environment:
      - AUTH_HEADER=r4HaS1AbangHaSAN
    volumes:
      - ./data:/app/data
    restart: unless-stopped

⁠API Endpoints

⁠Public Endpoints (No Authentication Required)
⁠Get All JSON Items
  • GET /json
  • Returns all JSON items in the store
⁠Get Specific JSON Item
  • GET /json/:id
  • Returns a specific JSON item by its UUID
  • This will return data from memory or from the data directory if the file exists
  • Add ?pretty=true query parameter to get pretty-printed JSON output
    • Example: /json/<UUID>?pretty=true
⁠Authenticated Endpoints (Authentication Required)

For all write operations, include the Authorization header (default):

Authorization: r4HaS1AbangHaSAN
⁠Create New JSON Item
  • POST /json
  • Creates a new JSON item with a random UUID
  • Body: Any valid JSON data
  • Returns the new item's ID and URL
⁠Replace JSON Item
  • PUT /json/:id
  • Replaces an existing JSON item completely
  • Body: New JSON data to replace the existing item
⁠Update JSON Item
  • PATCH /json/:id
  • Updates an existing JSON item partially
  • Body: JSON data with fields to update
⁠Delete JSON Item
  • DELETE /json/:id
  • Deletes an existing JSON item

⁠Usage Examples

⁠Using curl
⁠Create a new item:
curl -X POST http://localhost:8000/json \
  -H "Content-Type: application/json" \
  -H "Authorization: r4HaS1AbangHaSAN" \
  -d '{
    "title": "Example Item",
    "content": "This is a sample content",
    "author": "Test User"
  }'
⁠Get all items:
curl http://localhost:8000/json
⁠Get a specific item:
curl http://localhost:8000/json/<UUID>
⁠Get a specific item with pretty formatting:
curl http://localhost:8000/json/<UUID>?pretty=true
⁠Update an item partially:
curl -X PATCH http://localhost:8000/json/<UUID> \
  -H "Content-Type: application/json" \
  -H "Authorization: r4HaS1AbangHaSAN" \
  -d '{
    "content": "Updated content"
  }'
⁠Replace an item completely:
curl -X PUT http://localhost:8000/json/<UUID> \
  -H "Content-Type: application/json" \
  -H "Authorization: r4HaS1AbangHaSAN" \
  -d '{
    "title": "New Title",
    "content": "New content"
  }'
⁠Delete an item:
curl -X DELETE http://localhost:8000/json/<UUID> \
  -H "Authorization: r4HaS1AbangHaSAN"

⁠Automatic File Cleanup

The service automatically runs a scheduler at 00:00 (midnight) daily in the Asia/Jakarta timezone to remove files older than the configured number of days (default: 7 days).

⁠Data Storage

  • Each item is stored as both in-memory data and as an individual JSON file in the data directory
  • File names follow the pattern: data/<UUID>.json
  • The createdAt timestamp is automatically added to each stored item

⁠Repository

https://github.com/banghasan/dbjson⁠

Tag summary

Content type

Image

Digest

sha256:07c073613…

Size

73.9 MB

Last updated

11 months ago

docker pull banghasan/serverjson:main-36daeeb