Run locally
- Requires Go 1.21+.
- From the
srcdirectory:
cd src
go build
./bloggerThe server listens on :$PORT (default 8080).
Persistence
- Set
POSTS_JSONto change the file used for storage (default:posts.jsonin CWD). - Data is written atomically using a temporary file and rename.
- On startup, data is loaded from the JSON file if it exists.
API
-
GET
/api/posts- Returns a list of posts.
-
GET
/api/posts/:id- Returns a single post by id.
-
POST
/api/posts- Create a new post.
- Body:
{ "author": "name", "title": "title", "description": "text" }- PATCH
/api/posts/:id- Update any subset of fields.
- Body examples:
{ "title": "new value" }{ "author": "bob", "description": "updated", "content": "# New\n\nBody" }- DELETE
/api/posts/:idDelete a post.
Quick curl examples
# list
curl -s http://localhost:$PORT/api/posts
# create
curl -s -X POST http://localhost:$PORT/api/posts \
-H 'Content-Type: application/json' \
-d '{"author":"alice","title":"hello","description":"first"}'
# get by id
curl -s http://localhost:$PORT/api/posts/1
# patch
curl -s -X PATCH http://localhost:$PORT/api/posts/1 \
-H 'Content-Type: application/json' \
-d '{"parts":{"title":"Hello","description":"updated"}}'
# delete
curl -i -X DELETE http://localhost:$PORT/api/posts/1BASE_URL=https://blog.warpdrive.team // what url this is being hosted on
DISCORD_WEBHOOK_URL= // used for forwarding to discord