Q. What's the minimum amount of code needed to mock up a miniature Twitter back-end?
A. How comfortable are you with SQL?
Use the following commands to get up and running.
In one terminal window:
$ sudo apt update # updates package index
$ sudo apt install --yes ruby-foreman sqlite3 # manage Procfile and database
$ sudo apt install --yes python3-pip python3-flask-cors # required Python packages
$ python3 -m pip install sandman2 # used to expose API
$ export PATH="$HOME/.local/bin:$PATH"
$ git clone https://github.com/ProfAvery/cpsc349-project4
$ cd cpsc349-project4/api
$ make # creates database
$ foreman start # starts back-end
In another terminal window:
$ cd cpsc349-project4/
$ npm install
$ npm start # starts front-end
You can examine the data using the sandman2
Admin Interface.
See the following references for more information:
Operation | HTTP Method | URL |
---|---|---|
Create a user | POST | http://localhost:5000/users/ |
{
"username": "tester",
"email": "[email protected]",
"password": "testing"
}
Operation | HTTP Method | URL |
---|---|---|
Check a user's password | GET | http://localhost:5000/users/?username=ProfAvery&password=password |
Start following a user | POST | http://localhost:5000/followers/ |
{
"follower_id": 4,
"following_id": 2
}
Operation | HTTP Method | URL |
---|---|---|
Stop following a user | DELETE | http://localhost:5000/followers/6 |
Note that 6
is the id
of the entry in the followers
table, not the user_id
of either user.
Operation | HTTP Method | URL |
---|---|---|
Retrieve a user's timeline | GET | http://localhost:5000/followers/6 |
Retrieve the public timeline | GET | http://localhost:5000/followers/6 |
Search posts for a hashtag | GET | http://localhost:5000/posts/?text=%%%%23cpsc315%% |
Post a new message | POST | http://localhost:5000/posts/ |
{
"user_id": 4,
"text": "First poast!"
}
This version of the Mockroblog database includes additional data not included in Project 3:
- Likes
- Direct Messages
- Polls
The REST API exposed by sandman2
also allows additional types of queries
against existing data. See
the documentation for
details.