Get started with rails 6 API easily.
- Bundler -
gem install bundler
- Rails -
gem install rails
- Ruby - version 2.5 or higher
- Git
rails new app_name -d postgresql -m https://raw.githubusercontent.com/beyode/jumpstart-rails-api/master/template.rb --api
Or reference template.rb
locally if you have cloned this repo.
rails new app_name -d postgresql -m /path/to/jumpstart-rails-api/template.rb --api
- Authentication
- JWT - Custom devise Strategy
- Simple Token Authentication
Both are used together with your favorite Authentication gem devise.
Use INTERACTIVE=false
when running the generator to default to using JWT.
-
JSON::API This template uses jsonapi-serializer a fast JSON::API serializer gem(fork of Netflix fast_jsonapi) which make serialization of objects lightining fast.
-
Foreman For running multiple processes
Registration
Request
http --form POST 127.0.0.1:3000/api/v1/registration first_name='moses' last_name='gathuku' email='hello2@gathuku.com' password='secret'
Registration Sucess
{
"data": {
"attributes": {
"email": "hello2@gathuku.com",
"first_name": "moses",
"last_name": "gathuku"
},
"id": "3",
"type": "registration"
}
}
Registration Failure
{
"errors": {
"code": 422,
"details": [
"Email has already been taken"
]
}
}
Sign In
Sign In Success - Returns a JWT token
{
"data": {
"attributes": {
"email": "hello2@gathuku.com",
"jwt_token": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMsImV4cCI6MTU5MDQyODgxOH0.KQuzW2Yrtm8VL7kwlJlx9ipoVbd1jPlYez__wHzByck"
},
"id": "3",
"type": "sessions"
}
}
Sign In Failure
{
"errors": {
"code": 401,
"details": [
"Invalid email or password"
]
}
}
Unauthorized access response
{
"errors": {
"code": "401",
"detail": "You need to sign in or sign up before continuing.",
"title": "unauthorized"
}
}
Endpoint Not found
{
"errors": {
"code": 404,
"details": "Endpoint not found"
}
}