NO LONGER MAINTAINED. The Rails Rest portion of Blog App With Many Stacks is now the Replacement.
A starter project for building JSON Rails APIs with JWT for Rails 4.2.6 and Ruby 2.2
-
Make sure you have an
RAILS_ENV
environment variable set on your machine and have it set to 'development'. -
Update config/database.yml where applicable. Mainly, you will want to change the default database name from rails_api_starter to something else.
-
Install your packages by running
bundle install
. -
Make sure you have Mysql installed.
-
Create the database with
bundle exec rake db:create
-
Migrate the database with
bundle exec rake db:migrate
-
To get seed data run.
bundle exec rake db:seed
-
You can override any environment variables such as the mysql port with a dotenv file if you wish. Read more
-
Add your pre-push hook by creating a file by the name of
.git/hooks/pre-push
#!/bin/bash
echo "Tests will be run to ensure you don't break the build"
if bundle exec rspec
then
exit 0 # push will execute
fi
echo "=================================="
echo "Please fix the tests and commit again. If you intended to commit broken tests, then run 'git push --no-verify'"
exit 1 # push will not execute
- Run
chmod +x .git/hooks/pre-push
-
Start your mysql server
-
use
bundle exec rails s
to run the server.
Tests are written using rspec. You can run tests with the following:
bundle exec rspec
- You can download a sample postman collection from the data directory.
Authentication is handled via JWT and an XSRF Token. Analyzing in postman should suffice. You will need to make sure you have the 'Interceptor' extension installed since the JWT is being sent via a cookie.