Skip to content
This repository has been archived by the owner on Mar 26, 2022. It is now read-only.

Phase II: A Simple HTTPS Server

Kumin In edited this page Nov 4, 2016 · 23 revisions

API Endpoints

Login user

POST /api/v1/login

Creates and login the user by using their facebook profile.

Parameters:

Name Type Description
access_token String User's facebook access token

Response:

Response: 200
{
  "Session": "True",
  "user": {
    "_id": "581bfe92ddb3b4fe8d6184c8",
    "name": "Aaron Turner",
    "email": "",
    "profilePhotoURL": "graph.facebook.com/facebookId/picture",
    "__v": 0,
    "keywords": [
      "aaron",
      "turner"
    ],
    "pendingFriends": [],
    "friends": [],
    "facebook": {
      "id": "facebookId"
    }
  }
}

Get user information by id

GET /api/v1/user/:id

Retrieves the user information based on the Facebook ID.

Parameters:

Name Type Description
access_token String User's facebook access token
id String A User's facebook ID

Response:

Response: 200
{
  "_id": "581bfe8dddb3b4fe8d6184c7",
  "name": "Kumin In",
  "email": "[email protected]",
  "profilePhotoURL": "graph.facebook.com/facebookId/picture",
  "__v": 0,
  "keywords": [
    "abc",
    "@example",
    "com",
    "kumin"
  ],
  "pendingFriends": [],
  "friends": [],
  "facebook": {
    "id": "facebookId"
  }
}

Get public key for a user.

GET /api/v1/user/:id/publicKey


Update existing public key for the user.

PUT /api/v1/user/publicKey


Accept pending friend request

PUT /api/v1/user/friend/accept

Accepts a pending friend request for a given user.

Parameters:

Name Type Description
access_token String User's facebook access token
otherUserID String other user's facebook Id

Response:

Response: 201
{
  "message": "Successfully added friends"
}

Decline pending friend request

PUT /api/v1/user/friend/decline

Declines a pending friend request for a given user.

Parameters:

Name Type Description
access_token String User's facebook access token
otherUserID String other user's facebook Id

Response:

Response: 201
{
  "message": "Successfully removed pending friend."
}

Create new friend request

PUT /api/v1/user/friend/add

Creates a new pending friend request for the given user.

Parameters:

Name Type Description
access_token String User's facebook access token
otherUserID String other user's facebook Id

Response:

Response: 201
{
  "message": "Successfully added to pending list"
}

Accept pending friend request

PUT /api/v1/user/friend/delete

Remove a friend from the user's friend list.

Parameters:

Name Type Description
access_token String User's facebook access token
otherUserID String other user's facebook Id

Response:

Response: 201
{
  "message": "Successfully deleted friend."
}

Get all conversation for a user

GET /api/1/conversation

Retrieves All of the User's conversation.

Parameters:

Name Type Description
access_token String User's facebook access token

Response:

Response: 200
[
  {
    "_id": "581c030411270a049a33a051",
    "conversationID": "581bfe8dddb3b4fe8d6184c7_581bfe92ddb3b4fe8d6184c8",
    "date": "2016-11-04T05:40:28.773Z",
    "__v": 2,
    "message": [
      {
        "_id": "581c030411270a049a33a050",
        "message": "Hey, I can send a message to the server :^)!!",
        "from": "Aaron Turner",
        "date": "2016-11-04T03:39:48.638Z",
        "__v": 0
      },
      {
        "_id": "581c1f49432e5e0928829cec",
        "message": "This is a new message!",
        "from": "Kumin In",
        "date": "2016-11-04T05:40:25.465Z",
        "__v": 0
      }
    ],
    "members": [
      {
        "_id": "581bfe8dddb3b4fe8d6184c7",
        "name": "Kumin In",
        "email": "[email protected]",
        "profilePhotoURL": "graph.facebook.com/FacebookId/picture",
        "__v": 2,
        "keywords": [
          "example",
          "@example",
          "com",
          "kumin"
        ],
        "pendingFriends": [],
        "friends": [],
        "facebook": {
          "id": "FacebookId"
        }
      },
      {
        "_id": "581bfe92ddb3b4fe8d6184c8",
        "name": "Aaron Turner",
        "email": "",
        "profilePhotoURL": "graph.facebook.com/FacebookId/picture",
        "__v": 5,
        "keywords": [
          "aaron",
          "turner"
        ],
        "pendingFriends": [],
        "friends": [],
        "facebook": {
          "id": "FacebookId"
        }
      }
    ]
  }
]

Update a conversation for a user.

PUT /api/v1/conversation

Updates a conversation with a new message from a user.

Parameters:

Name Type Description
access_token String User's facebook access token
message String The message being sent
conversationID String ID for the conversation

Response:

Response: 201
{
  "_id": "581c030411270a049a33a051",
  "conversationID": "581bfe8dddb3b4fe8d6184c7_581bfe92ddb3b4fe8d6184c8",
  "date": "2016-11-04T05:40:28.773Z",
  "__v": 2,
  "message": [
    {
      "_id": "581c030411270a049a33a050",
      "message": "Hey, I can send a message to the server :^)!!",
      "from": "Aaron Turner",
      "date": "2016-11-04T03:39:48.638Z",
      "__v": 0
    },
    {
      "_id": "581c1f49432e5e0928829cec",
      "message": "This is a new message!",
      "from": "Kumin In",
      "date": "2016-11-04T05:40:25.465Z",
      "__v": 0
    }
  ],
  "members": [
    {
      "_id": "581bfe8dddb3b4fe8d6184c7",
      "name": "Kumin In",
      "email": "[email protected]",
      "profilePhotoURL": "graph.facebook.com/FacebookId/picture",
      "__v": 2,
      "keywords": [
        "example",
        "@example",
        "com",
        "kumin"
      ],
      "pendingFriends": [],
      "friends": [],
      "facebook": {
        "id": "FacebookId"
      }
    },
    {
      "_id": "581bfe92ddb3b4fe8d6184c8",
      "name": "Aaron Turner",
      "email": "",
      "profilePhotoURL": "graph.facebook.com/FacebookId/picture",
      "__v": 5,
      "keywords": [
        "aaron",
        "turner"
      ],
      "pendingFriends": [],
      "friends": [],
      "facebook": {
        "id": "FacebookId"
      }
    }
  ]
}

Create a new conversation for a user.

POST /api/v1/conversation

Create a new conversation for the users provided. Message Object is sent as a JSON Object in the body.

Parameter:

Name Type Description
access_token String User's facebook access token
message Object The message being sent

message Object:

{
	"access_token": "UserAccessToken",
	"message": "Hey, I can send a message to the server :^)!!",
	"members": ["581bfe8dddb3b4fe8d6184c7"]
}

Response:

Response: 201
{
  "_id": "581c030411270a049a33a051",
  "conversationID": "581bfe8dddb3b4fe8d6184c7_581bfe92ddb3b4fe8d6184c8",
  "date": "2016-11-04T03:39:48.638Z",
  "__v": 0,
  "message": [
    {
      "_id": "581c030411270a049a33a050",
      "message": "Hey, I can send a message to the server :^)!!",
      "from": "Aaron Turner",
      "date": "2016-11-04T03:39:48.638Z",
      "__v": 0
    }
  ],
  "members": [
    {
      "_id": "581bfe8dddb3b4fe8d6184c7",
      "name": "Kumin In",
      "email": "[email protected]",
      "profilePhotoURL": "graph.facebook.com/FacebookId/picture",
      "__v": 2,
      "keywords": [
        "example",
        "@example",
        "com",
        "kumin"
      ],
      "pendingFriends": [],
      "friends": [],
      "facebook": {
        "id": "FacebookId"
      }
    },
    {
      "_id": "581bfe92ddb3b4fe8d6184c8",
      "name": "Aaron Turner",
      "email": "",
      "profilePhotoURL": "graph.facebook.com/FacebookId/picture",
      "__v": 5,
      "keywords": [
        "aaron",
        "turner"
      ],
      "pendingFriends": [],
      "friends": [],
      "facebook": {
        "id": "FacebookId"
      }
    }
  ]
}

Postman Test Images

Imgur

Imgur

Imgur

Imgur

Imgur

Imgur

Imgur

Clone this wiki locally