Demo app that emulates a Twitter-like REST API. Utilizes Python Flask and Riak Data Types (CRDTs).
$ 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
$ 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
$ 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
$ sudo riak start
$ git clone [email protected]:rcgenova/riak-twitter-clone.git
$ cd riak-twitter-clone
$ sudo bash admin.bash
Start the API:
$ python app.py
Open another SSH tab and run the example commands below:
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 /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.)
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]"}'
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 /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 /api/v1.0/user/following/[USER_ID]
$ curl http://localhost:5000/riak-twitter-clone/api/v1.0/user/following/[email protected]
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 /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 /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 /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 /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]