A Go implementation of the Open Heart Protocol.
A hosted version of this is available at https://openheart.tylery.com/
Knock yourself out 😉
- JSON is permitted
POST https://openheart.tylery.com/example.com { "emoji": "🌾"}
GET https://openheart.tylery.com/example.com (200)
POST https://openheart.tylery.com/example.com (201 | 200)
Using plain text:
# curl
curl -X POST -d "💖" https://openheart.tylery.com/example.com
# fetch
fetch('https://openheart.tylery.com/example.com', {
method: 'POST',
body: '💖'
})Using form data:
# curl
curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "💖=" \
'https://openheart.tylery.com/example.com'
# fetch
fetch('https://openheart.tylery.com/example.com', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: '💖='
})Using JSON:
# curl
curl -X POST \
-H "Content-Type: application/json" \
-d '{"emoji": "💖"}' \
'https://openheart.tylery.com/example.com'
# fetch
fetch('https://openheart.tylery.com/example.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ emoji: '💖' })
})# curl
curl 'https://openheart.tylery.com/example.com'
# fetch
fetch('https://openheart.tylery.com/example.com')
# Response
{
"💖": 5,
"👍": 3,
"🌟": 1
}The server can be configured through command line flags or environment variables. Command line flags take precedence over environment variables.
| Flag | Environment Variable | Default | Description |
|---|---|---|---|
-http-port |
HTTP_PORT |
4444 | Port number for the HTTP server |
-dsn |
DB_DSN |
user:password@tcp(host:port)/database |
Database connection string |
-version |
- | - | Display version and exit |
The database connection string (DSN) must be in the format: user:password@tcp(host:port)/database
For local development with Docker, you can use the included docker-compose.yml which requires the following environment variables:
DB_ROOT_PASSWORD=<root password>
DB_NAME=<database name>
DB_USER=<database user>
DB_PASSWORD=<database password>Using command line flags:
./openheart-protocol -http-port 8080 -dsn "user:pass@tcp(localhost:3306)/mydb"Using environment variables:
export HTTP_PORT=8080
export DB_DSN=user:pass@tcp(localhost:3306)/mydb
./openheart-protocol| Method | Path | Description |
|---|---|---|
| GET | /status |
Health check endpoint |
| GET | /{url} |
Get emoji reactions for a URL |
| POST | /{url} |
Add emoji reaction to a URL |
- Start the database:
docker compose up -d- Run the server:
go run ./cmd/apiThe server includes automatic database migrations on startup.
