Git Product home page Git Product logo

rails-5-api's Introduction

Build Status

RAILS 5 API TEMPLATE

With JWT Authentication

How to use

Download

Setup

  • bundle install
  • copy .env.example file to .env and add required values
  • rake db:setup

Examples using curl

Creating a new user

Request

curl -H "Content-Type: application/json" \
     -X POST -d '{"email":"[email protected]","password":"12345678"}' \
     http://localhost:3000/api/user/sign_up

Response Sign up success message and a JWT token

{
  "message":"User created successfully",
  "auth_token":"eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo4LCJleHAiOjE1MTQyMjYxMDN9.ADOGnYeexJpJj8SCHZHL_JFJ3iza9MmXTyWb8wGSFws"
}

Logging in

Request

curl -H "Content-Type: application/json" \
     -X POST -d '{"email":"[email protected]","password":"12345678"}' \
     http://localhost:3000/api/user/sign_in

Response Login success message and a JWT token

{
  "access_token":"eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo4LCJleHAiOjE1MTQyMjY0MjB9.u-6sECl-_GVj5JfE90ExGcGC5QR8xuJDh_FDbAFI7-w",
  "message":"Login Successful"
}

Accessing a protected endpoint

Resquest Replace the Authorization token with a valid one, after sign_in or sign_up

curl -H "Content-Type: application/json" \
     -H "Authorization: eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo4LCJleHAiOjE1MTQyMjcxMjF9.HRXFrrWU9ZRBCaYflOIAPskEcpNVcZQ7neGOwGTBqeM" \
     -X GET http://localhost:3000/api/users

Response

[
  {"email":"[email protected]"},
  {"email":"[email protected]"},
  {"email":"[email protected]"}
]

Rake Tasks

Rename/Personalize the application

rake rename[NewName]

To Do list

  • Add user sign up
  • Add user sign in
  • Add JWT authentication
  • Add password reset feature
  • Add password_confirmation field on Sign up
  • Add email token-confirmation after Sign up
  • Add Rack Attack gem, and configure it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.