For any application with a need to build its own social network, "Friends Management" is a common requirement which usually starts off simple but can grow in complexity depending on the application's use case.
Usually, applications would start with features like "Friend", "Unfriend", "Block", "Receive Updates" etc.
Develop an API server that does simple "Friend Management" based on the User Stories below.
- Python
- Django>2.0
- Django Rest Framework
- I had problems learning the framework while doing
- drf-yasg
- Neo4j
- A graph database is probably best suited for this social network question
- It did take some time to learn the cypher query format
- django_neomodel
- I needed something that interfaced seamlessly with neo4j for django
- neomodel
- Actually leverage on Django Rest Framework's authentication service - No authentication at the moment
- My code is bad for situations where the number of data in the db is huge. I will need to optimize all the calls
- run the docker compose command to get the neo4j and django server up and running.
git clone https://github.com/stlimtat/sp-test.git
cd <path>/sp-test
docker-compose up
- Once the docker is running, you can browse to the link below to view the APIs
- Create Friends
POST /friends/
{
friends:
[
'[email protected]',
'[email protected]'
]
}
This should create the entries [email protected] and [email protected], and then link them up as friends in the database
- Get all persons recorded in system
GET /friends/
This provides a full list of all the persons recorded in the database
- Get persons who are friends of specific user
GET /friends/
{
email: '[email protected]'
}
Or
GET /friends/[email protected]
I was not sure how to do this properly. I can always handle this via a POST but just seems to contradict the REST requirements. So in the end, I just left it as-is. I will be happily using GET with a request body.
This API returns the list of all friends of [email protected]
- Get common friends between 2 users
GET /friends/
{
friends:
[
'[email protected]',
'[email protected]'
]
}
Again the issue of how to handle JSON body with GET This API returns the list of all common friends of the listed email ids.
- Subscribe to updates from an email address
POST /subscribe/
{
"requestor": "[email protected]",
"target": "[email protected]"
}
This should connect from the requestor to the target with a relationship of SUBSCRIBE.
This relationship is directional.
The SUBSCRIBE relationship will need to be obtained later.
If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.
The code in this project is licensed under Apache 2.0 license.