A simple Sinatra app providing a RESTful API for async messaging
In project root directory run:
bundle install
rake db:setup
You can run the app with: ruby simple_chat.rb
Two endpoints are exposed:
/user/:id/messages
- You can
GET
a list messages in JSON format for a specific user id from this endpoint.
- You can
/messages
- You can
POST
a message here.
- You can
First setup and seed the test database with:
RACK_ENV=test rake db:setup
Then run: rspec
/user/:id/messages
returns a hash in the following format:
{
"sent": [
{
"recipient": "recipient name",
"body": "message body",
"timestamp": "timestamp"
}
],
"received": [
{
"sender": "sender name",
"body": "message body",
"timestamp": "timestamp"
}
]
}
All fields are String
objects, except timestamps, which are Time
objects.
/messages
accepts messages in multipart form encoding with the followingString
fields:sender
,recipient
,body