Giter Club home page Giter Club logo

todo_app's Introduction

TODO app

Here I'll add some comments along making this small TODO API-only app. I use RubyMine from JetBrains as IDE, and Ubuntu 14.04.4 LTS as dev environment.

Versioning of APIs is skipped for simplicity.

Start a new API-only Rails 5.0 project:

rails new todo_app --api

Add few gems to Gemfile:

gem 'rspec-rails' # for testing with RSpec - TODO

gem 'bcrypt' # password hashing

gem 'active_model_serializers' # model serializer

gem 'rack-cors' # cross domain access

I decided to go for a version with authentication, but without categories handling. This means I will have two models - User and Task.

User model I made without email field for simplicity. Authentication will be handled via token field assigned ONLY once randomly to each user during the creation of the user and stored in the database. Better practice would be to generate this token each time the user logs in, and remove it on logout + add expiration time. Here I made a simple implementation by myself, but one can use already made libraries like Knock, Diverse, Authlogic and others for JWT based authentication. Probably a smart idea would be to cache the token in the Redis so that server will not call database on each request checking if token is correct and/or to which user it is assigned.

rails generate scaffold User username:string password:digest token:string

rails generate migration add_index_to_users_token

Task model is simple with just few fields and reference to User model.

rails generate scaffold Task title:string done:boolean user:references

Create user:

curl -X POST -H "Content-Type: application/json" -d '{"user": {"username": USERNAME,"password": PASSWORD } } ' "http://localhost:3000/users/"

Login user:

curl -X POST -H "Content-Type: application/json" -d '{"user": {"username": USERNAME,"password": PASSWORD } } ' "http://localhost:3000/login"

Get all users:

curl -H "Authorization: Token token=TOKEN" http://localhost:3000/users

Deployed to Heroku:

https://guarded-peak-24627.herokuapp.com

Still TODO (ironically), just for fun:

  • testing with RSpec
  • use fixtures for unit testing
  • refactor unit tests for controllers
  • make a simple client in VueJS
  • implement categories

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.