net_backend

API reference

Examples

10. Examples: curl#

shell
API=https://your-server.example

# Server info (no auth)
curl -sS "$API/v1/info"
# {"protocol":1,"min_protocol":1,"modules":["auth","chat","storage"]}

# Register (logs in at once)
curl -sS "$API/v1/auth/register" -H 'content-type: application/json' \
  -d '{"email":"player@example.com","password":"correct horse battery","display_name":"Player One"}'
# {"account":{"id":42,...},"tokens":{"token_type":"Bearer","access_token":"nbsa_...","access_expires_at":...,"refresh_token":"nbsr_...","refresh_expires_at":...}}

# Log in
curl -sS "$API/v1/auth/login" -H 'content-type: application/json' \
  -d '{"email":"player@example.com","password":"correct horse battery"}'

ACCESS=nbsa_...    # tokens.access_token
REFRESH=nbsr_...   # tokens.refresh_token

# Who am I
curl -sS "$API/v1/account" -H "authorization: Bearer $ACCESS"

# Refresh (single use: store the new pair)
curl -sS "$API/v1/auth/refresh" -H 'content-type: application/json' \
  -d "{\"refresh_token\":\"$REFRESH\"}"

# Save an object (create only if new)
curl -sS -X PUT "$API/v1/storage/saves/slot-1" -H "authorization: Bearer $ACCESS" \
  -H 'content-type: application/json' -d '{"value":{"level":3,"gold":250},"if_version":0}'
# {"collection":"saves","key":"slot-1","version":1,"updated_at":...}

# Load it (the ETag header is the version)
curl -sS -i "$API/v1/storage/saves/slot-1" -H "authorization: Bearer $ACCESS"

# Overwrite only version 1
curl -sS -X PUT "$API/v1/storage/saves/slot-1" -H "authorization: Bearer $ACCESS" \
  -H 'content-type: application/json' -d '{"value":{"level":4,"gold":300},"if_version":1}'
# a stale version: 409 {"error":{"code":"version_conflict","message":"...","details":{"current_version":2}}}

# List a collection (no values), then delete
curl -sS "$API/v1/storage/saves?limit=20" -H "authorization: Bearer $ACCESS"
curl -sS -X DELETE "$API/v1/storage/saves/slot-1?if_version=2" -H "authorization: Bearer $ACCESS"

# Chat over HTTP: public rooms, a room's history, open a DM
curl -sS "$API/v1/chat/rooms" -H "authorization: Bearer $ACCESS"
curl -sS "$API/v1/chat/rooms/12/messages?limit=50" -H "authorization: Bearer $ACCESS"
curl -sS "$API/v1/chat/dm" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{"user":77}'

# Password reset (website flow)
curl -sS "$API/v1/auth/password/forgot" -H 'content-type: application/json' -d '{"email":"player@example.com"}'
curl -sS "$API/v1/auth/password/reset" -H 'content-type: application/json' \
  -d '{"token":"<token from the mail link>","new_password":"another long passphrase"}'

# Log out (this session; with an expired access token send {"refresh_token":"..."} instead)
curl -sS "$API/v1/auth/logout" -H "authorization: Bearer $ACCESS" -H 'content-type: application/json' -d '{}'

# The API documents
curl -sS "$API/v1/openapi.json" -o openapi.json
curl -sS "$API/v1/asyncapi.json" -o asyncapi.json

Generated from API.md (repository commit e25edb9, file sha256 3db87f7bba70).