Skip to content

Ruby on Rails API project to store a data of the users using authentication with JWT, API reversional versioning, rswag integration specs with OpenAPI documentation &.

Notifications You must be signed in to change notification settings

georgiybykov/udatapp

Repository files navigation

udatapp

RuboCop RSpec

Ruby on Rails API project to store a data of the users.


The project includes and consists of:

  • Ruby 2.7.5
  • Ruby on Rails 6.1.5
  • RSpec as framework for tests
  • rswag for integration specs and generated API documentation by OpenAPI Specification
  • Custom authentication with JWT
  • API reversional versioning
  • dry-rb stack

Fetch and start the project:

$ git clone git@github.com:georgiybykov/udatapp.git
$ cd qna

# Install dependencies:
$ bundle install

$ cp config/database.yml.sample config/database.yml

$ bundle exec bin/rails db:create
$ bundle exec bin/rails db:migrate

Run server:

$ bundle exec bin/rails server

Then visit: http://localhost:3000


Authentication

  • To create a new user:
curl -X POST localhost:3000/api/v2/registration \
     -H 'Content-type: application/json' \
     -d '{ "email": "udatapp@email.com", "password": "123456789" }'
  • To authenticate the user:
curl -X POST localhost:3000/api/v2/login \
     -H 'Content-type: application/json' \
     -d '{ "email": "udatapp@email.com", "password": "123456789" }'

On successful login will be returned:

{
  "access_token": <token>,
  "expires_at": <datetime>
}

The token will be expired after 24 hours by default.

You should use this token for further requests in Authorization header, for example:

curl -X GET localhost:3000/api/v2/notes \
     -H 'Content-type: application/json' \
     -H 'Authorization: <token>'

Run tests:

$ bundle exec rspec

Run linter:

$ bundle exec rubocop

Generate rswag API documentation:

$ bundle exec rails rswag:specs:swaggerize

API documentation will be available at:

http://localhost:3000/api-docs/index.html

Examples:

  • API-docs main page:

API-docs main page

  • /note/:id current v2 endpoint:

/note/:id endpoint

  • /note/:id deprecated v1 endpoint:

/note/:id deprecated endpoint


Good luck! May the force be with you!

About

Ruby on Rails API project to store a data of the users using authentication with JWT, API reversional versioning, rswag integration specs with OpenAPI documentation &.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published