Web API that receives and processes device readings. There is a requirement not to persist data to disk but rather store in-memory. Thus, in order to avoid possible race conditions, the web server is WEBrick instead of Puma because it's single-threaded.
-
Set your environment variables
cp -i ./.env.template ./.env
-
Install dependencies
-
Native
bundle install
-
Docker
docker compose build
-
-
Native
bin/rails server
-
Docker
docker compose up
-
Native
RAILS_ENV=test bin/rspec
-
Docker
docker compose run --rm -e "RAILS_ENV=test" web bin/rspec
-
Native
RAILS_ENV=test bin/rubocop
-
Docker
docker compose run --rm web bin/rubocop
- Swagger docs are generated via
rswagand can be accessed at http://localhost:3000/api-docs - Request specs defined in
spec/requests/api/v1define the swagger definition for each endpoint - To regenerate the
swagger.yamlfile, run the following command, validate the swagger docs, and commit the changes:- Native
RAILS_ENV=test bin/rails rswag
- Docker
docker compose run --rm -e "RAILS_ENV=test" web bin/rails rswag
- app:
controllersandforms- note: forms are intended validate input parameters
- bin: executables used for various tasks related to running, testing and linting
- spec: tests
- note: requests subdirectory contains the swagger definitions for the API endpoints
- swagger: location of auto-generated swagger file used for API documentation
- Better validation of nested input parameters (e.g.
timestampandcount)- consider using
json-schemaordry-validationgems
- consider using
- Optimize by using Rails cache instead of a class variable to store data in-memory
- Logging and monitoring using
SentryandDatadog - Rate limiting
- Extract schema defined in
spec/requests/api/v1/readings_spec.rbfor the post request into a separate file in aspec/schemasdirectory