/jumpstart-rails-api

Jumpstart your next Rails API project with a bunch of features.

Primary LanguageRubyMIT LicenseMIT

Jumpstart Rails API

Get started with rails 6 API easily.

Requirements

  • Bundler - gem install bundler
  • Rails - gem install rails
  • Ruby - version 2.5 or higher
  • Git

Creating a new application

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

Features

  1. Authentication

Both are used together with your favorite Authentication gem devise. Use INTERACTIVE=false when running the generator to default to using JWT.

  1. 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.

  2. Foreman For running multiple processes

Authentication

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"
    }
}