The Friends microservice manages friendships and friend requests between users. It provides APIs for sending, accepting, and rejecting friend requests, as well as retrieving friend lists and mutual friends. This service integrates with the Users microservice to fetch user details and with the Posts microservice to provide friend-related content recommendations.
- Sending friend requests
- Accepting friend requests
- Rejecting friend requests
- Retrieving friend lists
- Retrieving mutual friends
- Friend suggestions
- Integration with Users microservice for user details
- Integration with Posts microservice for content recommendations
- Efficient message propagation using RabbitMQ
- Secure communication with JWT authentication
- RESTful API for friend operations
- Django
- Django Restframework
- Neo4j
- RabbitMQ
- Redis
SECRET_KEY=
NEO4J_AUTH=
NEO4j_HOST=
USERS_SERVICE=http://users:8000
RABBITMQ_DEFAULT_USER=
RABBITMQ_DEFAULT_PASS=
RABBITMQ_HOST=
QUEUE_LIST=friends,posts,users
CURRENT_QUEUE=friends
- HTTP Authentication, scheme: basic
Code samples
GET /api/friends/me/ HTTP/1.1
Accept: application/json
GET /me/
Get the number of friend requests received by the user
Example responses
200 Response
{
"request_count": 0
}
Status | Meaning | Description | Schema |
---|---|---|---|
200 | OK | none | UserRequestCount |
401 | Unauthorized | Unauthorized | None |
Code samples
GET /api/friends/suggestions/{id}/ HTTP/1.1
Accept: application/json
GET /suggestions/{id}/
Get the friend suggestions for the user
Name | In | Type | Required | Description |
---|---|---|---|---|
id | path | string | true | none |
Example responses
200 Response
{
"next": "http://example.com",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"full_name": "string",
"mutual_friends": 0,
"mutual_friends_name_list": ["string"],
"is_friend": true,
"sent_request": true,
"received_request": true
}
]
}
Status | Meaning | Description | Schema |
---|---|---|---|
200 | OK | none | UserList |
401 | Unauthorized | Unauthorized | None |
Code samples
DELETE /api/friends/suggestions/{id}/ HTTP/1.1
DELETE /suggestions/{id}/
Delete a friend suggestion
Name | In | Type | Required | Description |
---|---|---|---|---|
id | path | string | true | none |
Status | Meaning | Description | Schema |
---|---|---|---|
204 | No Content | No Content | None |
401 | Unauthorized | Unauthorized | None |
404 | Not Found | User not found | None |
Code samples
GET /api/friends/users/friends/requests/ HTTP/1.1
Accept: application/json
GET /users/friends/requests/
Get the friend requests received by the user
Example responses
200 Response
{
"next": "http://example.com",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"req_id": "b0b81fb9-c6eb-4a11-855e-45e48af9566f",
"full_name": "string",
"created_at": "2019-08-24T14:15:22Z",
"sent_request": true,
"received_request": true,
"mutual_friends": 0,
"mutual_friends_name_list": ["string"]
}
]
}
Status | Meaning | Description | Schema |
---|---|---|---|
200 | OK | none | FriendRequestList |
401 | Unauthorized | Unauthorized | None |
Code samples
POST /api/friends/users/friends/requests/ HTTP/1.1
Content-Type: application/json
Accept: application/json
POST /users/friends/requests/
Send a friend request to another user
Body parameter
{
"user_to_id": "7380bf92-4931-437e-ac11-314f80255fbd"
}
Name | In | Type | Required | Description |
---|---|---|---|---|
body | body | FriendRequest | true | none |
Example responses
201 Response
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"req_id": "b0b81fb9-c6eb-4a11-855e-45e48af9566f",
"full_name": "string",
"created_at": "2019-08-24T14:15:22Z",
"sent_request": true,
"received_request": true,
"mutual_friends": 0,
"mutual_friends_name_list": ["string"]
}
Status | Meaning | Description | Schema |
---|---|---|---|
201 | Created | none | FriendRequestObject |
400 | Bad Request | Bad Request | None |
401 | Unauthorized | Unauthorized | None |
Code samples
POST /api/friends/users/friends/requests/action/ HTTP/1.1
Content-Type: application/json
POST /users/friends/requests/action/
Accept or reject a friend request
Body parameter
{
"action": "accept",
"request_id": "266ea41d-adf5-480b-af50-15b940c2b846"
}
Name | In | Type | Required | Description |
---|---|---|---|---|
body | body | FriendRequestAction | true | none |
Status | Meaning | Description | Schema |
---|---|---|---|
204 | No Content | No Content | None |
401 | Unauthorized | Unauthorized | None |
404 | Not Found | Friend request not found | None |
Code samples
GET /api/friends/users/friends/requests/sent/ HTTP/1.1
Accept: application/json
GET /users/friends/requests/sent/
Get the friend requests sent by the user
Example responses
200 Response
{
"next": "http://example.com",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"req_id": "b0b81fb9-c6eb-4a11-855e-45e48af9566f",
"full_name": "string",
"created_at": "2019-08-24T14:15:22Z",
"sent_request": true,
"received_request": true,
"mutual_friends": 0,
"mutual_friends_name_list": ["string"]
}
]
}
Status | Meaning | Description | Schema |
---|---|---|---|
200 | OK | none | FriendRequestList |
401 | Unauthorized | Unauthorized | None |
Code samples
GET /api/friends/users/{id}/ HTTP/1.1
Accept: application/json
GET /users/{id}/
Get the user details by user id
Name | In | Type | Required | Description |
---|---|---|---|---|
id | path | string | true | none |
Example responses
200 Response
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"full_name": "string",
"is_friend": true,
"sent_request": true,
"received_request": true
}
Status | Meaning | Description | Schema |
---|---|---|---|
200 | OK | none | UserRetrieve |
401 | Unauthorized | Unauthorized | None |
404 | Not Found | User not found | None |
Code samples
GET /api/friends/users/{id}/friends/ HTTP/1.1
Accept: application/json
GET /users/{id}/friends/
Get the user friends by user id
Name | In | Type | Required | Description |
---|---|---|---|---|
page | query | integer | false | A page number within the paginated result set. |
id | path | string | true | none |
Example responses
200 Response
{
"next": "http://example.com",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"full_name": "string",
"mutual_friends": 0,
"mutual_friends_name_list": ["string"],
"is_friend": true,
"sent_request": true,
"received_request": true
}
]
}
Status | Meaning | Description | Schema |
---|---|---|---|
200 | OK | none | UserList |
401 | Unauthorized | Unauthorized | None |
404 | Not Found | User not found | None |
Code samples
GET /api/friends/users/{id}/friends/mutual/ HTTP/1.1
Accept: application/json
GET /users/{id}/friends/mutual/
Get the mutual friends between two users
Name | In | Type | Required | Description |
---|---|---|---|---|
page | query | integer | false | A page number within the paginated result set. |
id | path | string | true | none |
Example responses
200 Response
{
"next": "http://example.com",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"full_name": "string",
"mutual_friends": 0,
"mutual_friends_name_list": ["string"],
"is_friend": true,
"sent_request": true,
"received_request": true
}
]
}
Status | Meaning | Description | Schema |
---|---|---|---|
200 | OK | none | UserList |
401 | Unauthorized | Unauthorized | None |
404 | Not Found | User not found | None |
{
"request_count": 0
}
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
request_count | integer | true | none | none |
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"full_name": "string",
"mutual_friends": 0,
"mutual_friends_name_list": ["string"],
"is_friend": true,
"sent_request": true,
"received_request": true
}
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
id | string(uuid) | true | none | none |
full_name | string | true | none | none |
mutual_friends | integer | true | none | none |
mutual_friends_name_list | [string] | true | none | none |
is_friend | boolean | true | none | none |
sent_request | boolean | true | none | none |
received_request | boolean | true | none | none |
{
"next": "http://example.com",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"full_name": "string",
"mutual_friends": 0,
"mutual_friends_name_list": ["string"],
"is_friend": true,
"sent_request": true,
"received_request": true
}
]
}
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
next | string(uri) | true | none | none |
results | [User] | true | none | none |
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"req_id": "b0b81fb9-c6eb-4a11-855e-45e48af9566f",
"full_name": "string",
"created_at": "2019-08-24T14:15:22Z",
"sent_request": true,
"received_request": true,
"mutual_friends": 0,
"mutual_friends_name_list": ["string"]
}
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
id | string(uuid) | true | none | none |
req_id | string(uuid) | true | none | none |
full_name | string | true | none | none |
created_at | string(date-time) | true | none | none |
sent_request | boolean | true | none | none |
received_request | boolean | true | none | none |
mutual_friends | integer | true | none | none |
mutual_friends_name_list | [string] | true | none | none |
{
"next": "http://example.com",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"req_id": "b0b81fb9-c6eb-4a11-855e-45e48af9566f",
"full_name": "string",
"created_at": "2019-08-24T14:15:22Z",
"sent_request": true,
"received_request": true,
"mutual_friends": 0,
"mutual_friends_name_list": ["string"]
}
]
}
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
next | string(uri) | true | none | none |
results | [FriendRequestObject] | true | none | none |
{
"user_to_id": "7380bf92-4931-437e-ac11-314f80255fbd",
"req_id": "string",
"created_at": "2019-08-24T14:15:22Z",
"mutual_friends_count": 0,
"mutual_friends_name_list": ["string"]
}
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
user_to_id | string(uuid) | true | none | none |
req_id | string | false | read-only | none |
created_at | string(date-time) | false | read-only | none |
mutual_friends_count | integer | false | read-only | none |
mutual_friends_name_list | [string] | false | read-only | none |
{
"action": "accept",
"request_id": "266ea41d-adf5-480b-af50-15b940c2b846"
}
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
action | string | true | none | none |
request_id | string(uuid) | true | none | none |
Property | Value |
---|---|
action | accept |
action | reject |
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"full_name": "string",
"is_friend": true,
"sent_request": true,
"received_request": true
}
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
id | string(uuid) | true | none | none |
full_name | string | true | none | none |
is_friend | boolean | true | none | none |
sent_request | boolean | true | none | none |
received_request | boolean | true | none | none |
This project is licensed under the MIT License. See the LICENSE file for details.