Skip to content

Latest commit

 

History

History
124 lines (97 loc) · 1.66 KB

File metadata and controls

124 lines (97 loc) · 1.66 KB

REST API Specification

Simple REST API for the in-memory data store.

Base URL

http://localhost:8080

String Operations

Set String

POST /strings
Content-Type: application/json

{
  "key": "username",
  "value": "john",
  "ttl": 3600  // optional, seconds
}

Get String

GET /strings/{key}

Update String

PUT /strings/{key}
Content-Type: application/json

{
  "value": "new_value"
}

List Operations

Set List

POST /lists
Content-Type: application/json

{
  "key": "items",
  "value": ["apple", "banana"],
  "ttl": 3600  // optional, seconds
}

Get List

GET /lists/{key}

Push to List

POST /lists/{key}/push
Content-Type: application/json

{
  "value": "orange"
}

Pop from List

POST /lists/{key}/pop

General Operations

Delete Key

DELETE /keys/{key}

Response Format

Success:

{
  "success": true,
  "data": "result"
}

Error:

{
  "success": false,
  "error": "Error message"
}

Examples

# Set a string
curl -X POST http://localhost:8080/strings \
  -H "Content-Type: application/json" \
  -d '{"key":"user","value":"john"}'

# Get the string
curl http://localhost:8080/strings/user

# Create a list
curl -X POST http://localhost:8080/lists \
  -H "Content-Type: application/json" \
  -d '{"key":"items","value":["apple","banana"]}'

# Add to list
curl -X POST http://localhost:8080/lists/items/push \
  -H "Content-Type: application/json" \
  -d '{"value":"orange"}'

# Remove from list
curl -X POST http://localhost:8080/lists/items/pop

# Delete key
curl -X DELETE http://localhost:8080/keys/user