The goal of this application was to demonstrate building a backend API and front-end consumer of the same application. It was meant to be done in 4-6 hours. In addition to the front-end application, be sure to check out the specs as well. And let me know if you have any questions.
This application requires:
- Ruby 2.3.1
- Rails 4.2.6
- Sending a status update message without a status is valid, and in that case, the status for the update would be the last known status. If no status updates exist, then the update is invalid.
With a bit more time, here are some things I'd look to improve:
- Stand-alone documentation for the API
- Grouping status updates under some sort of "incidents" model.
- Might consider using Rails 5 and ActionCable as a means of rendering real-time updates to the system status via WebSockets.
- Install ruby 2.3.1
> gem install bundler
> bundle
> bundle exec rake db:setup
> bundle exec rails server
> bundle exec rake db:test:prepare
> bundle exec rspec
- Check out the site at localhost:3000, verify the empty state is in place and looks like:
curl -XPOST -H "Content-type: application/json" -d '{"system_status": "UP", "message": "Hello world."}' 'localhost:3000/api/v1/status.json'
- Refresh and see:
curl -XPOST -H "Content-type: application/json" -d '{"system_status": "DOWN", "message": "Oh no! The system is down!"}' 'localhost:3000/api/v1/status.json'
- Refresh and see:
Requests should be in the following format:
curl -XPOST -H "Content-type: application/json" -d '{"system_status": "UP", "message": "Hello world."}' 'localhost:3000/api/v1/status.json'
Parameter | Description |
---|---|
system_status | This is the status you want to set. Can be "UP" or "DOWN" |
message | This is a message you want to include in the status update. This is not required. |
Note: If a status update is sent without a system_status
, it is assumed that the system status has not changed and should inherit the status from the previous update.
The response to the API will be in the following format and always include the current system status at the conclusion of handling the request:
{
"current_status": {
"system_status": "DOWN",
"message": "Some message."
}
}
If there is an error in the API call, you will receive a 400 (Bad Request) response, as well as an errors
object that indicates what was wrong with the request, a la:
{
"current_status": {
"system_status": "DOWN",
"message": "Some message."
},
"errors": {
"system_status": [
"Status must be one of UP or DOWN."
]
}
}