Rails starter template for bootstrapping Rails API projects.
Firstly, you need to change the values of the development and test keys in secrets.yml. This file is accessible at APP_ROOT/config/secrets.yml
To generate new secret values run:
$ bundle exec rake secret
You'd need to run this twice to generate replacements for both development and test keys in the secrets.yml file
Once secrets are changed, run:
$ bundle install
This installs dependencies present in the Gemfile.
User Authentication is handled through JSON web tokens. The authentication flow is as follows:
- Create an account
- Log into your account to obtain JSON web token
- Pass token in Authorization Header/Request Parameters for subsequent requests.
- Log out once done (optional)
An example of a token passed in with the Authorization Header is as follows:
Authorization: token <api-token>
An example of a token passed in through request parameters is as follows:
GET /auth/logout?token=<api-token>
where
<api-token>
in both cases should be replaced by actual token assigned
To create an account, you'll need to send in user attributes in JSON format. Required attributes to create an account are:
name
, email
, password
, password_confirmation
If arguments are incorrect, a message is returned stating which entry was incorrect
To log in to an account, you'll need to send in account attributes in JSON format. Required attributes to login to your account are:
email
, password
A successful response to the Login request contains the JSON web token assigned, and its expiry date.
EndPoint | Functionality |
---|---|
POST /auth/login | Logs a user in |
GET /auth/logout | Logs a user out |
POST /users/new | Create a new user |
User authentication is implemented with the JWT gem. For more information, see https://github.com/jwt/ruby-jwt for more information.
Service objects were implemented by extending the SimpleCommand gem. See https://github.com/nebulab/simple_command for more information.
Faker and FactoryGirlRails were used to generate random data/random models used while testing. See https://github.com/stympy/faker and https://github.com/thoughtbot/factory_girl_rails for more information.
The default testing framework used is Minitest. To run all tests, run:
$ bundle exec rake
-
Fork it by visiting - https://github.com/rahdio/rails-api-starter/fork
-
Create your feature branch
$ git checkout -b new_feature
-
Contribute to code
-
Commit changes made
$ git commit -a -m 'descriptive_message_about_change'
-
Push to branch created
$ git push origin new_feature
-
Then, create a new Pull Request