Skip to content

szorfein/Erebe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Erebe

This server is an API server with ruby & rails and mongoid, used to build website.
Will work with a client like Nyx write with ionic.

Install

You have to install rails 5 and mongodb v3.6.

$ git clone https://github.com/szorfein/Erebe.git
$ cd Erebe
$ rails s

Server start at http://localhost:3000.

API with curl

Example to create a new user:

$ curl --url 'http://127.0.0.1:3000/users' \
  --header 'content-type:application/json' \
  --request POST \
  --data '{"user":{"email":"robss@corp.uk","password":"ppeeeeee","password_confirmation":"ppeeeeee"}}'

Delete an user with id:

$ curl --request DELETE --url 'http://127.0.0.1:3000/users/5aa945f2fbf3af1f82b7b342'

Login:

$ curl --url 'http://127.0.0.1:3000/login' --header 'content-type:application/json' --request POST --data '{"email":"robss@corp.uk","password":"ppeeeeee"}'

Add a new book, you need a jwt token:

$ curl --url 'http://127.0.0.1:3000/books' --header "Authorization":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjp7IiRvaWQiOiI1YWE5NDYyM2ZiZjNhZjI3ZTNiY2NmZDAifX0.hlZf_CzNxmB_DjtM20bU-d6ou2TObrbFYdB7B_VZd-4" --header 'content-type:application/json' --request POST --data '{"book":{"name":"kari"}}'

Build from scratch

  • Rails
$ mkdir project && cd project/
$ rails new ./ --api -T --skip-active-record
$ echo "gem 'mongoid', '~> 6.1.0'" >> Gemfile
$ echo "gem 'rack-cors'" >> Gemfile
$ bundle install

+ Mongoid, use x509 auth

$ rails g mongoid:config

And look config/mongoid.yml, it take 2 var from env, you can set in .bashrc or other shell:

  • export SHAKEN_C="<path to mongo-client.pem"
  • export MONGO_CA="<path to mongo-ca.pem>"

And generate database with rails:

$ rails db:create
$ rails generate scaffold book name:string
$ rails db:migrate
$ mkdir db
$ vim db/seeds.rb

Create somes datas:

Book.create!([
  { name: 'Copying and Pasting from Stack Overflow' },
  { name: 'Trying Stuff Until it Works' }
])

And populate database with this.

$ rails db:seed
$ rails s

Look at http://localhost:3000/book.json must have our books.

Links: