Skip to content

Twitter-like REST API on top of Riak. Uses Data Types (CRDTs) and Search.

License

Notifications You must be signed in to change notification settings

rcgenova/riak-twitter-clone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

riak-twitter-clone

Demo app that emulates a Twitter-like REST API. Utilizes Python Flask and Riak Data Types (CRDTs).

Setup

Python pre-requisites

$ sudo yum install -y python-setuptools gcc python-devel libffi-devel openssl-devel
$ sudo easy_install pip
$ sudo pip install flask
$ sudo pip install riak

Install Riak

$ wget http://s3.amazonaws.com/downloads.basho.com/riak/2.1/2.1.3/rhel/7/riak-2.1.3-1.el7.centos.x86_64.rpm
$ sudo rpm -Uvh riak-2.1.3-1.el7.centos.x86_64.rpm

Set ulimit

$ echo 'riak soft nofile 65536' | sudo tee --append /etc/security/limits.conf
$ echo 'riak hard nofile 65536' | sudo tee --append /etc/security/limits.conf
$ echo "$USER soft nofile 65536" | sudo tee --append /etc/security/limits.conf
$ echo "$USER hard nofile 65536" | sudo tee --append /etc/security/limits.conf

Start Riak

$ sudo riak start

Clone riak-twitter-clone

$ git clone [email protected]:rcgenova/riak-twitter-clone.git

Create bucket types

$ cd riak-twitter-clone
$ sudo bash admin.bash

Usage

Start the API:

$ python app.py

Open another SSH tab and run the example commands below:

New user

POST /api/v1.0/user/new -d {"user":[USER_ID],"password":[PASSWORD]}

$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/user/new -H "Content-Type: application/json" -d '{"user_id":"[email protected]","password":"passnow"}'
$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/user/new -H "Content-Type: application/json" -d '{"user_id":"[email protected]","password":"passnow"}'
$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/user/new -H "Content-Type: application/json" -d '{"user_id":"[email protected]","password":"passnow"}'

Get user

GET /api/v1.0/user/[USER_ID]

$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/[email protected]
$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/[email protected]

(The only property currently stored is the password hash.)

Follow user

PUT /api/v1.0/user/follow -d {"primary_user_id":[PRIMARY_USER_ID],"secondary_user_id":[SECONDARY_USER_ID]}

(primary follows secondary)

$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/user/follow -H "Content-Type: application/json" -d '{"primary_user_id":"[email protected]","secondary_user_id":"[email protected]"}'
$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/user/follow -H "Content-Type: application/json" -d '{"primary_user_id":"[email protected]","secondary_user_id":"[email protected]"}'
$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/user/follow -H "Content-Type: application/json" -d '{"primary_user_id":"[email protected]","secondary_user_id":"[email protected]"}'

Unfollow user

PUT /api/v1.0/user/unfollow -d {"primary_user_id":[PRIMARY_USER_ID],"secondary_user_id":[SECONDARY_USER_ID]}

(primary unfollows secondary)

$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/user/unfollow -H "Content-Type: application/json" -d '{"primary_user_id":"[email protected]","secondary_user_id":"[email protected]"}'

Get followers

GET /api/v1.0/user/followers/[USER_ID]

$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/followers/[email protected]
$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/followers/[email protected]

Get following

GET /api/v1.0/user/following/[USER_ID]

$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/following/[email protected]

New post

POST /api/v1.0/post -d {"user":[USER_ID],"text":[TEXT]}

$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/post -H "Content-Type: application/json" -d '{"user_id":"[email protected]","text":"rgenova post #1"}'
$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/post -H "Content-Type: application/json" -d '{"user_id":"[email protected]","text":"user2 post #1"}'
$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/post -H "Content-Type: application/json" -d '{"user_id":"[email protected]","text":"user3 post #1"}'
$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/post -H "Content-Type: application/json" -d '{"user_id":"[email protected]","text":"user3 post #2"}'
$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/post -H "Content-Type: application/json" -d '{"user_id":"[email protected]","text":"user3 post #3"}'
$ curl -i -X POST http://localhost:5000/riak-twitter-clone/api/v1.0/post -H "Content-Type: application/json" -d '{"user_id":"[email protected]","text":"user3 post #4"}'

Get post

GET /api/v1.0/post/[POST_ID]

$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/post/[POST_ID]

(Substitute a post_id returned from a new post command above.)

Get user timeline

GET /api/v1.0/user/timeline/[USER_ID]

$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/timeline/[email protected]
$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/timeline/[email protected]
$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/timeline/[email protected]

Get user posts

GET /api/v1.0/user/posts/[USER_ID]

$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/posts/[email protected]
$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/posts/[email protected]

Get stats

GET /api/v1.0/user/stats/[USER_ID]

$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/stats/[email protected]
$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/stats/[email protected]
$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/stats/[email protected]

About

Twitter-like REST API on top of Riak. Uses Data Types (CRDTs) and Search.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published