-
Notifications
You must be signed in to change notification settings - Fork 3
Web Service API & Documentation
Currently, we allow connectivity with the following apps:
- https://social.hydrated.app/api
- https://connectify-cl.herokuapp.com (our second instance)
- https://frandzone.herokuapp.com
NOTE: We added several new servers (ex: https://young-plains-33934.herokuapp.com, https://newpee.herokuapp.com) but it appears they are overloading our server with requests and causing our app to crash so we are no longer attempting to contact them in the hopes of keeping our server functioning.
We have database Server Model entries for each other group we connect with, as well as a Server Model for our own group. Each entry contains the username and password we use for authentication when we send out requests.
For example, group 1 provided us with the username "https://connectifyapp.herokuapp.com/" and the password "1". So in our database we have an entry for the host https://social.hydrated.app/api with the previously mentioned username and password.
We have given credential information to group 1 as well (username: "group1", password "group1"). Group 1 needs to send group1/group1 as basic auth in their requests to us that require authentication.
This means when other servers want to access our API, we would create a username/password for them to use as well. This also means when we want to disallow API access we would simply deactivate their special permissions account in our database.
All API endpoints currently require basic authentication.
Important: We use/expect a custom X-User header with an author API URL (ex: "X-User" : "https://connectifyapp.herokuapp.com/author/e756d5bb-f7a6-4ae9-97f2-12693f6e9e4d") in requests we send and accept in our API.
We use the value of this custom header on queries that require information about the querying author. For example, http://service/author/posts
returns posts visible to the authenticated author. Groups sending requests to this endpoint should use the X-User and basic authentication using the username/password given to them by us. When receiving this query, we check for the X-User header, fetch the author information, and return the appropriate results. As a last ditch backup, if an X-User header is not provided, we will use the provided username/password in the request's basic authentication and will return posts visible to the author whose username was provided.
Groups we are connected to are expected to use this X-User convention as well.
Currently, for remote server posts, our home feed page fetches and displays a limit of 25 posts per remote server currently. There is no limitation on local posts displayed and fetched by our home feed page.
Aside from the above notes, we have not deviated from the provided API spec in our implementations of the endpoints.
URL: http://service/posts
Accepted Methods: GET
Description: Returns all posts marked as public on the server.
Example:
{
"query": "posts",
"count": 2,
"size": 50,
"next": null,
"previous": null,
"posts": [
{
"title": "everyone still can see this ",
"source": "http://127.0.0.1:8000/posts/4173e290-7541-4db1-9625-d895ce722720",
"origin": "/posts/4173e290-7541-4db1-9625-d895ce722720",
"description": "",
"contentType": "text/plain",
"content": "Content goes here",
"author": {
"id": "http://127.0.0.1:8000/author/ea121d8e-aec3-4e80-a6ed-0c02011bde30",
"host": "http://127.0.0.1:8000/",
"displayName": "b",
"url": "http://127.0.0.1:8000/author/ea121d8e-aec3-4e80-a6ed-0c02011bde30",
"github": ""
},
"categories": [],
"comments": [
{
"author": {
"id": "http://127.0.0.1:8000/author/ea121d8e-aec3-4e80-a6ed-0c02011bde30",
"host": "http://127.0.0.1:8000/",
"displayName": "b",
"url": "http://127.0.0.1:8000/author/ea121d8e-aec3-4e80-a6ed-0c02011bde30",
"github": ""
},
"comment": "6th comment",
"contentType": "text/plain",
"published": "2019-03-29T02:16:42.678733+00:00",
"id": "2e4fdad4-4181-458d-8f96-3328d727b01b"
},
{
"author": {
"id": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"host": "http://127.0.0.1:8000/",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"comment": "comment 3",
"contentType": "text/plain",
"published": "2019-03-28T20:55:56.900401+00:00",
"id": "35d56743-5b81-4253-85c9-c0f1eaba2b3c"
},
{
"author": {
"id": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"host": "http://127.0.0.1:8000/",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"comment": "comment 3",
"contentType": "text/plain",
"published": "2019-03-28T20:55:53.598326+00:00",
"id": "16edd269-76ee-4d5b-aa21-331bcbf2ca90"
},
{
"author": {
"id": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"host": "http://127.0.0.1:8000/",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"comment": "comment 3",
"contentType": "text/plain",
"published": "2019-03-28T20:55:50.835290+00:00",
"id": "5882ca8a-049b-4d5f-b20b-e2b5baa3d2fc"
},
{
"author": {
"id": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"host": "http://127.0.0.1:8000/",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"comment": "comment \r\n2",
"contentType": "text/plain",
"published": "2019-03-28T20:55:45.735593+00:00",
"id": "1226ea1f-6f5d-4ac6-9591-5b758dd8a9ad"
}
],
"published": "2019-03-28T04:54:25.219764+00:00",
"id": "4173e290-7541-4db1-9625-d895ce722720",
"visibility": "PUBLIC",
"visibleTo": [],
"unlisted": false
},
{
"title": "everyone can see this",
"source": "http://127.0.0.1:8000/posts/1f6a4229-6c5f-4604-8414-1932646014c3",
"origin": "/posts/1f6a4229-6c5f-4604-8414-1932646014c3",
"description": "",
"contentType": "text/plain",
"content": "fasfsafsaf",
"author": {
"id": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"host": "http://127.0.0.1:8000/",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"categories": [],
"comments": [
{
"author": {
"id": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"host": "http://127.0.0.1:8000/",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"comment": "your comment now",
"contentType": "text/plain",
"published": "2019-03-28T23:46:55.719756+00:00",
"id": "551509dc-ed26-4b31-a250-7dc99c9af00d"
},
{
"author": {
"id": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"host": "http://127.0.0.1:8000/",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"comment": "my comment now",
"contentType": "text/plain",
"published": "2019-03-28T23:46:45.649884+00:00",
"id": "6d168337-8a07-4e83-93ec-e31d6e7a2bad"
}
],
"published": "2019-03-28T04:27:20.829429+00:00",
"id": "1f6a4229-6c5f-4604-8414-1932646014c3",
"visibility": "PUBLIC",
"visibleTo": [],
"unlisted": false
}
]
}
Accepted Methods: GET
Description: Returns a single post with id = {post_id}.
Example:
{
"query": "getPost",
"posts": {
"title": "Melee HD Announced",
"source": "http://connectifyapp.herokuapp.com/posts/1afcabb7-4a54-4eb8-87e8-f474d15996de",
"origin": "https://social.hydrated.app/api/posts/1afcabb7-4a54-4eb8-87e8-f474d15996de",
"description": "jk",
"contentType": "text/plain",
"content": "Just kidding, RIP Melee\r\nSent from social hydrated btw\r\n\r\nheres the link: https://social.hydrated.app/Post/1afcabb7-4a54-4eb8-87e8-f474d15996de/",
"author": {
"id": "https://connectifyapp.herokuapp.com/author/8074379f-9088-49b1-8b28-c1724ed83bb5",
"host": "https://connectifyapp.herokuapp.com/",
"displayName": "bhlewka",
"url": "https://connectifyapp.herokuapp.com/author/8074379f-9088-49b1-8b28-c1724ed83bb5",
"github": "https://github.com/bhlewka"
},
"categories": [],
"comments": [
{
"author": {
"id": "https://connectifyapp.herokuapp.com/author/8074379f-9088-49b1-8b28-c1724ed83bb5",
"host": "https://connectifyapp.herokuapp.com/",
"displayName": "bhlewka",
"url": "https://connectifyapp.herokuapp.com/author/8074379f-9088-49b1-8b28-c1724ed83bb5",
"github": "https://github.com/bhlewka"
},
"comment": "btw smash ultimate is not good",
"contentType": "text/plain",
"published": "2019-03-29T21:10:29.758452+00:00",
"id": "a71f4e42-0529-4cbf-a2c6-87546a411a1d"
}
],
"published": "2019-03-29T21:10:28+00:00",
"id": "1afcabb7-4a54-4eb8-87e8-f474d15996de",
"visibility": "PUBLIC",
"visibleTo": [],
"unlisted": false
}
}
Accepted Methods: GET
Description: Returns a single post's comment data.
Example:
{
"query": "comments",
"count": 2,
"size": 50,
"next": null,
"previous": null,
"comments": [
{
"author": {
"id": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"host": "http://127.0.0.1:8000/",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"comment": "your comment now",
"contentType": "text/plain",
"published": "2019-03-28T23:46:55.719756+00:00",
"id": "551509dc-ed26-4b31-a250-7dc99c9af00d"
},
{
"author": {
"id": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"host": "http://127.0.0.1:8000/",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"comment": "my comment now",
"contentType": "text/plain",
"published": "2019-03-28T23:46:45.649884+00:00",
"id": "6d168337-8a07-4e83-93ec-e31d6e7a2bad"
}
]
}
Accepted Methods: GET
Description: Returns all posts that are visible to the currently authenticated user.
Example:
{
"query": "posts",
"count": 3,
"size": 1,
"next": "http://127.0.0.1:8000/posts/?page=2&size=1",
"previous": null,
"posts": [
{
"title": "everyone can see this",
"source": "http://127.0.0.1:8000/posts/1",
"origin": "http://127.0.0.1:8000/posts/1",
"description": "",
"contentType": "text/plain",
"content": "body",
"author": {
"id": "http://127.0.0.1:8000/author/1",
"host": "127.0.0.1:8000",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/1"
},
"comments": [
{
"author": {
"id": "http://127.0.0.1:8000/author/1",
"host": "127.0.0.1:8000",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/1"
},
"comment": "comment 1",
"contentType": "text/plain",
"published": "2019-03-25T21:56:49+00:00",
"id": 1
},
{
"author": {
"id": "http://127.0.0.1:8000/author/1",
"host": "127.0.0.1:8000",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/1"
},
"comment": "2",
"contentType": "text/plain",
"published": "2019-03-26T06:08:39.155452+00:00",
"id": 2
},
{
"author": {
"id": "http://127.0.0.1:8000/author/1",
"host": "127.0.0.1:8000",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/1"
},
"comment": "3",
"contentType": "text/plain",
"published": "2019-03-26T06:08:43.082358+00:00",
"id": 3
},
{
"author": {
"id": "http://127.0.0.1:8000/author/1",
"host": "127.0.0.1:8000",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/1"
},
"comment": "comment 4",
"contentType": "text/plain",
"published": "2019-03-26T22:29:43.907136+00:00",
"id": 5
},
{
"author": {
"id": "http://127.0.0.1:8000/author/1",
"host": "127.0.0.1:8000",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/1"
},
"comment": "comment 5",
"contentType": "text/plain",
"published": "2019-03-26T22:42:35.809824+00:00",
"id": 6
}
],
"published": "2019-03-25T20:54:40.822030+00:00",
"id": 1,
"visibility": "..."
}
]
}
Accepted Methods: GET
Description: Returns all posts made by {AUTHOR_ID} visible to the currently authenticated user.
{
"query": "posts",
"count": 1,
"size": 50,
"next": null,
"previous": null,
"posts": [
{
"title": "everyone can see this",
"source": "http://127.0.0.1:8000/posts/1f6a4229-6c5f-4604-8414-1932646014c3",
"origin": "/posts/1f6a4229-6c5f-4604-8414-1932646014c3",
"description": "",
"contentType": "text/plain",
"content": "fasfsafsaf",
"author": {
"id": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"host": "http://127.0.0.1:8000/",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"categories": [],
"comments": [
{
"author": {
"id": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"host": "http://127.0.0.1:8000/",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"comment": "your comment now",
"contentType": "text/plain",
"published": "2019-03-28T23:46:55.719756+00:00",
"id": "551509dc-ed26-4b31-a250-7dc99c9af00d"
},
{
"author": {
"id": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"host": "http://127.0.0.1:8000/",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"comment": "my comment now",
"contentType": "text/plain",
"published": "2019-03-28T23:46:45.649884+00:00",
"id": "6d168337-8a07-4e83-93ec-e31d6e7a2bad"
}
],
"published": "2019-03-28T04:27:20.829429+00:00",
"id": "1f6a4229-6c5f-4604-8414-1932646014c3",
"visibility": "PUBLIC",
"visibleTo": [],
"unlisted": false
}
]
}
Accepted Methods: GET, POST
Description: GET Returns a list of friends of the author with id {author_id} in the following format -
{
"query": "friends",
"author": "1",
"authors": [
"https://127.0.0.1:8000/author/2",
"https://127.0.0.1:8000/author/3"
]
}
Post accepts a list of user ID's and returns the list with non-friends removed
Accepted Methods: GET, POST
Description: Returns a list of the comments in a post. GET returns information in the following format
{
"query": "comments",
"count": 5,
"size": 50,
"next": null,
"previous": null,
"comments": [
{
"author": {
"id": "http://127.0.0.1:8000/author/1",
"host": "127.0.0.1:8000",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/1"
},
"comment": "comment 1",
"contentType": "text/plain",
"published": "2019-03-25T21:56:49+00:00",
"id": 1
},
{
"author": {
"id": "http://127.0.0.1:8000/author/1",
"host": "127.0.0.1:8000",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/1"
},
"comment": "2",
"contentType": "text/plain",
"published": "2019-03-26T06:08:39.155452+00:00",
"id": 2
},
{
"author": {
"id": "http://127.0.0.1:8000/author/1",
"host": "127.0.0.1:8000",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/1"
},
"comment": "3",
"contentType": "text/plain",
"published": "2019-03-26T06:08:43.082358+00:00",
"id": 3
},
{
"author": {
"id": "http://127.0.0.1:8000/author/1",
"host": "127.0.0.1:8000",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/1"
},
"comment": "comment 4",
"contentType": "text/plain",
"published": "2019-03-26T22:29:43.907136+00:00",
"id": 5
},
{
"author": {
"id": "http://127.0.0.1:8000/author/1",
"host": "127.0.0.1:8000",
"displayName": "a",
"url": "http://127.0.0.1:8000/author/1"
},
"comment": "comment 5",
"contentType": "text/plain",
"published": "2019-03-26T22:42:35.809824+00:00",
"id": 6
}
]
}
POST expects:
{
"query":"addComment",
"post":"http://127.0.0.1:8000/posts/4173e290-7541-4db1-9625-d895ce722720",
"comment":{
"author":{
"id":"http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838,
"host":"http://127.0.0.1:8000/",
"displayName":"a",
"url":"http://127.0.0.1:8000/author/a27c5826-e80a-41d3-be53-82887138b838",
"github": ""
},
"comment":"comment 3",
"contentType":"text/markdown",
"published":"2019-03-28T20:55:56.900401+00:00",
"id":"35d56743-5b81-4253-85c9-c0f1eaba2b3c"
}
}
and returns this on success
{
"query": "addComment",
"success":true,
"message":"Comment Added"
}
and returns this on fail
{
"query": "addComment",
"success":true,
"message":"Comment not allowed"
}
Accepted Methods: GET
Description: Returns information about the provided author in the following format
{
"id": "http://127.0.0.1:8000/author/3/",
"host": "127.0.0.1:8000",
"displayName": "peterdisplaynam",
"url": "http://127.0.0.1:8000/author/3/",
"friends": [
{
"id": "https://127.0.0.1:8000/author/1",
"host": "https://127.0.0.1:8000/",
"displayName": "peter",
"url": "https://127.0.0.1:8000/author/1"
},
{
"id": "https://127.0.0.1:8000/author/2",
"host": "https://127.0.0.1:8000/",
"displayName": "peter2",
"url": "https://127.0.0.1:8000/author/2"
}
],
"github": "peter.github.com",
"firstName": "Firstname",
"lastName": "Lastname",
"email": "[email protected]",
"bio": "this is my bio"
}
Accepted Methods: GET
Description: Returns information about the friendship between two authors and will say if they are friends or not
{
"friends": true,
"query": "friends",
"authors": [
"https://connectifyapp.herokuapp.com/author/de305d54-75b4-431b-adb2-eb6b9e546013",
"https://connectifyapp.herokuapp.com/author/gf305d54-75b4-431b-adb2-eb6b9e546069"
]
}
{
"friends": false,
"query": "friends",
"authors": [
"https://connectifyapp.herokuapp.com/author/de305d54-75b4-431b-adb2-eb6b9e546013",
"https://connectifyapp.herokuapp.com/author/gf305d54-75b4-431b-adb2-eb6b9e546069"
]
}
Accepted Methods: POST
Description: Receives a friend request and adds a relationship between the sender's ID and the receiver's ID
# to make a friend request, POST to http://service/friendrequest
# returns 200 OK
{
"query":"friendrequest",
"author": {
"id":"https://connectifyapp.herokuapp.com/author/de305d54-75b4-431b-adb2-eb6b9e546013",
"host":"https://connectifyapp.herokuapp.com",
"displayName":"Jameston Vones"
"url":"https://connectifyapp.herokuapp.com/author/de305d54-75b4-431b-adb2-eb6b9e546013",
},
"friend": {
"id":"https://connectifyapp.herokuapp.com/author/de305d54-75b4-431b-adb2-eb6b9e637281",
"host":"https://connectifyapp.herokuapp.com",
"displayName":"Tolulu Akinadala",
"url":"https://connectifyapp.herokuapp.com/author/de305d54-75b4-431b-adb2-eb6b9e546013",
}
}
Accepted Methods: POST
Description: This endpoint is used internally by the web app to process accepting or denying friend requests and is called using AJAX when the user clicks an accept/deny button on the friend page. This allows all the logic to be performed in the API endpoint. This endpoint requires authentication. This endpoint would not be made public and would not be publicly accessible, but we are showing it for grading purposes.
{
"query":"processrequest",
"action": "ACCEPT", # either "ACCEPT" or "DENY"
"IdOfFriendToAddOrDeny": "de305d54-75b4-431b-adb2-eb6b9e637281",
"IdOfLoggedInUser": "ce254d54-45b4-031a-bd24-426b9e633a42"
}
- API Spec: https://raw.githubusercontent.com/peterweckend/group-project-cmput404/master/example-article.json
- Examples of setting up API viewsets: https://www.django-rest-framework.org/api-guide/viewsets/#api-reference
- Router information (the Simple Router table is very helpful): https://www.django-rest-framework.org/api-guide/routers/
- Permissions and Authentication in Routers: https://www.django-rest-framework.org/api-guide/permissions/
- Returning Exceptions In the API: https://www.django-rest-framework.org/api-guide/exceptions/