Skip to content

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

License

Notifications You must be signed in to change notification settings

beyode/jumpstart-rails-api

Repository files navigation

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='[email protected]' password='secret'

# curl -H "Content-Type: application/json" -d @register.json localhost:3000/api/v1/registration

Registration Sucess

{
    "data": {
        "attributes": {
            "email": "[email protected]",
            "first_name": "moses",
            "last_name": "gathuku"
        },
        "id": "3",
        "type": "registration"
    }
}

Registration Failure

{
    "errors": {
        "code": 422,
        "details": [
            "Email has already been taken"
        ]
    }
}

Sign In

Request;

curl -H "Content-Type: application/json" -d @signin.json localhost:3000/api/v1/sessions

Sign In Success - Returns a JWT token

{
    "data": {
        "attributes": {
            "email": "[email protected]",
            "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"
    }
}

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages