This is a simple Sinatra application that provides a RESTful API for a user-associated key-value store. Users can sign up, store complex JSON objects associated with a key, and retrieve them using a unique ID.
- User signup and token-based authentication.
- Store, retrieve, update, and delete complex JSON objects.
- Each user's data is isolated from others.
- Data persistence using PStore.
-
Clone the repository:
git clone git@github.com:mmatongo/moa.git
cd moa
-
Install the required gems:
bundle install
-
Run the application:
ruby moa.rb
- Endpoint:
/signup
- Method:
POST
- Data:
json {"username": "your_username"}
- Response: A unique token for authentication.
- Endpoint:
/:username/:key
- Method:
POST
- Headers:
Authorization: your_token
- Data: Any valid JSON object.
- Response: A unique ID for the stored object.
- Endpoint:
/:username/:key/:id
- Method:
GET
- Headers:
Authorization: your_token
- Response: The stored JSON object.
- Endpoint:
/:username/:key/:id
- Method:
PUT
- Headers:
Authorization: your_token
- Data: Updated JSON object.
- Endpoint:
/:username/:key/:id
- Method:
DELETE
- Headers:
Authorization: your_token
-
Signup:
curl -X POST -H "Content-Type: application/json" -d '{"username": "mmatongo"}' http://127.0.0.1:4567/signup
-
Store a new object (e.g., under the key "profile"):
curl -X POST -H "Content-Type: application/json" -H "Authorization: ae7814054b59235ce80ee44e926f77c175291186c5f5d7472e" -d '{"name": "John", "age": 30, "city": "New York"}' http://127.0.0.1:4567/mmatongo/profile
This will return a unique ID for the object.
-
Get the object by key and ID (e.g., "profile" and the returned ID):
curl -X GET -H "Authorization: ae7814054b59235ce80ee44e926f77c175291186c5f5d7472e" http://127.0.0.1:4567/mmatongo/profile/unique_id
-
Update the object by key and ID:
curl -X PUT -H "Content-Type: application/json" -H "Authorization: ae7814054b59235ce80ee44e926f77c175291186c5f5d7472e" -d '{"name": "Jane", "age": 25, "city": "Los Angeles"}' http://127.0.0.1:4567/mmatongo/profile/unique_id
-
Delete the object by key and ID:
curl -X DELETE -H "Authorization: ae7814054b59235ce80ee44e926f77c175291186c5f5d7472e" http://127.0.0.1:4567/mmatongo/profile/unique_id
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License.