Ruby Grape application for REST API with ActiveRecord, RSpec, Swagger
The application receives URLs(string) and creates shortened links.
- Ruby 2.4.2
- PostgreSQL
To run application on docker:
-
Please install Docker and Docker-Compose
-
Clone the project
-
To create the database.yml please run the following script on the project root:
$ cp config/database.yml.sample config/database.yml
- Run following commands on the project root:
$ docker-compose build
$ docker-compose up
# Open another terminal and run:
$ docker-compose run web bundle exec rake db:create db:migrate
To execute tests, run following commands:
$ docker-compose run web bundle exec rake db:migrate RACK_ENV=test #(the first time only)
$ docker-compose run web bundle exec rspec
- Clone poject
- Run bundler:
$ bundle install
Create database.yml:
$ cp config/database.yml.sample config/database.yml
Before the next step please change the host value in config/database.yml from db
to your_host_url
- Create database and run migrations:
$ bundle exec rake db:create db:migrate
- Run application:
$ rackup -p 3000
To execute tests, run following commands:
$ bundle exec rake db:migrate RACK_ENV=test #(the first time only)
$ bundle exec rspec
Enter the root application address in the browser:
http://localhost:3000
To avoid any excessive complexity I used DBMS PostgreSQL. My opinion - PostgreSQL is the classic solution and it should be enough for long time. In the future(if necessary), we can make the following optimization:
- Use Redis for the cache storage (it will make the uniqueness checking process faster).
- If we don't need the absolute accuracy of the redirects number, we can move increment to the background job.
- In case if the 'Links' - table becames huge we can use some full-text search engine such as Elasticsearch or Sphinx. But now it would be overkill.
The software is available as open source under the terms of the MIT License.