Skip to content

marcosvieiraftw/rails-api-quick-starter

Repository files navigation

Quick Starter | Rails 6.0.1 & Ruby 2.6.5

Hi fellows this project has the intuit to share solutions for the most common needs in fresh projects. It will boost your start and create a fully configured project along with great tools to keep your quality up. The project has one module named User which is used to authenticate.

Summary

  • API Only.
  • Authentication through JSON Web Token | Knock
  • Authorization (ACL) pre-configured and ready to go | Pundit
  • Virtualized with Docker and Docker-compose in separated containers for database (Postgres) and application.
  • All JSON responses serialized and ready to go | Netflix Fast Json API
  • Along with serialization, there's the metadata object to work with server-side pagination, boosting your application performance | Pagy
  • Soft deletion configured for sensitive entities | Soft Deletion
  • User model configured to save password with OpenBSD bcrypt() hashing algorithm | bcrypt
  • CORS configured to accept requests from any domain. BE CAREFUL: change it before production release.
  • All response strings centralized on i18n files. By default, application is using EN-US but you can change it by creating yml files for you idiom. For more click here.
  • API documented with Postman on documentation/ folder.
  • VSCode configuration to run Rubocop lint on code while you develop to save your time. You'll need docker-linter and ruby-rubocop extensions to properly work.
  • Ruby style guide with Rubocop using Shopify rules.
  • Automated test suite: Rspec, Factory bot, shoulda-matchers, faker, simplecov and database_cleaner. There're examples of Request Why to use Request specs instead of obsolete Controllers spec and Models tests along with Factories for User, Rspec shared examples, helpers to sanitize JSON responses and to create authentication valid headers.

Soon (Not available yet)

  • Reset, forgot and change password services integrated with AWS Simple Email Service.
  • Active Storage for files and images integrated with AWS S3 Bucket.
  • Facebook and Google social login.
  • Bitbucket pipeline configuration to run Continuous Integration and Continuous Delivery.

Prerequisites

Installation

  • Clone the repository and navigate to the folder.
  • Create empty .env file on project root.
  • Run $ docker-compose up --build, docker will download the images and create the containers, it might take a while. Before finish, it will run start.sh file which will configure database (Create, migrate and seeds).
  • If you have Rails binary locally open another instance of terminal and run $ EDITOR="vi --wait" rails credentials:edit.
  • If you don't you can execute $ docker exec -it quick_starter_api bash and generate the master.key with # EDITOR="vi --wait" rails credentials:edit from inside the container. It will create the config/master.key which is required to work with JWT auth.
  • The server will be up on 3000 port, you can access now by localhost:3000

Getting Started

  • Run application with $ docker-compose up (After the first docker-compose up --build it's not necessary to run with --build again)
  • Login with User from seed by sending a POST to localhost:3000/api/v1/login with JSON body:
{
  "auth": {
    "email": "[email protected]",
    "password": "123"
  }
}

it will return an object with JWT token. Take it and use on header Authentication: Bearer TOKEN_JWT in other requests, like GET localhost:3000/api/v1/users

  • For futher information about API documentation you can import to Postman the collections from documentation/api_postman_collections
  • Your application is ready to go!

Running the tests

Inside the project folder execute $ docker exec -it quick_starter_api bash and then run # rspec after running all tests it will generate a coverage/ folder with the report in HTML format.

Running static code analyzer

Inside the project folder execute $ docker exec -it quick_starter_api bash and then run # rubocop

Contributing

Please check this repo's CONTRIBUTING.md file for guidelines on how to contribute. Your pull request is welcome!

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

Common functionalities used in most projects ready to go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages