Skip to content

Chat API documentation

Nebojsa Zoric edited this page Mar 5, 2018 · 1 revision

Overview

This document describes available API calls and provides example of resources that make up Company API.

  • Root URL and data formats
  • Authentication
  • Errors
  • User resources
  • Conversation resources
  • Message resources

Root URL and data formats

Every request starts with /api (if started locally for example, it is localhost:4000/api). All data is received and sent as JSON.

Authentication

Every API call requires basic authentication. To get a token you must first register. After completing registration you can login to get authentication token.

Login

POST /api/login/

Parameters:

  • email: String and
  • password: String

Returns:

  • User object,
  • Token and
  • Expiration value.

Request Example:

{
	"creds" : {
            "email": "[email protected]",
	    "password": "/fXLpFJV8u9dWcd"
	}
}

Response Example:

{
    "data": {
        "user": {
            "subname": "Doe",
            "password": "/fXLpFJV8u9dWcd",
            "name": "John",
            "job": "CEO",
            "id": 1,
            "email": "[email protected]"
        },
        "token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJDb21wYW55QXBpIiwiZXhwIjoxNTIyNDA2MzY4LCJpYXQiOjE1MTk5ODcxNjgsImlzcyI6IkNvbXBhbnlBcGkiLCJqdGkiOiIyZmE3OTU3Ni1mMmIzLTQ0MWMtOGZkNy1lOTE3OGUwZjA4OTciLCJuYmYiOjE1MTk5ODcxNjcsInN1YiI6IlVzZXI6MSIsInR5cCI6ImFjY2VzcyJ9.X7cYX3_McHzwqCsQo-tTYsXUG14SMk0S1yNWzj3qJ6gf2EqFeGDlqTQI93k9_KdU9hZRkcrz5yePsU4SJFaGQQ",
        "expire": 1522406368
    }
}

Logout

DELETE /api/logout

Parameters:

  • None

Returns:

  • Notification about successful logout

Response Example:

{
    "data": "Success logout"
}

Errors

Forming and sending bad request will result in appropriate HTTP response code. Usual response codes are:

  • 401 - Unauthorized and
  • 422 - Unprocessable Entity.

User resource

User object has next attributes:

  • id: Integer,
  • name: String,
  • subname: String,
  • email: String,
  • job: String and
  • password: String.

Registration

POST /api/users/

Parameters:

  • name: String,
  • subname: String,
  • email: String,
  • job: String and
  • password: String.

Returns:

  • User object

Request Example:

{ 
	"user" : {
		"name": "John",
		"subname": "Doe",
		"email": "[email protected]",
		"job": "CEO"
	}
}

Response Example:

{
    "subname": "Doe",
    "password": "QFB0zLvkkXLoZ98",
    "name": "Jane",
    "job": "CEO",
    "id": 2,
    "email": "[email protected]"
}

Password change

PUT /api/users/:id

Parameters:

  • password: String

Returns:

  • User new password

Request Example:

{ 
	"password": "johndoe"
}

Response Example: "johndoe"

Get all users

GET /api/users

Parameters:

  • None

Returns:

  • List of User objects

Response Example:

[
    {
        "subname": "Doe",
        "password": "QFB0zLvkkXLoZ98",
        "name": "Jane",
        "job": "CEO",
        "id": 2,
        "email": "[email protected]"
    },
    {
        "subname": "Doe",
        "password": "johndoe",
        "name": "John",
        "job": "CEO",
        "id": 1,
        "email": "[email protected]"
    }
]

Conversation resources

Conversation has next attributes:

  • id: Integer - Identification of conversation,
  • sender_id: Integer - Message sender id,
  • recipient_id: Integer - Message recipient id and
  • status: String - Conversation status

Create conversation

POST /api/conversations/

Parameters:

  • recipient_id

Returns:

  • Conversation object

Request Example:

{ 
	"recipient": 2
}

Response Example:

{
    "status": null,
    "id": 1
}

Get all conversations

GET /api/conversations/

Parameters:

  • None

Returns:

  • List of Conversation objects

Response Example:

[
    {
        "status": null,
        "id": 1
    }
]

Message resources

Message has next attributes:

  • content: String - Message content,
  • date: Date - Date of creation,
  • conversation_id: Integer - To which conversation this message belongs and
  • sender_id: Integer - Id of message sender.

Get all messages

GET /api/messages

Parameters:

  • conv_id

Returns:

  • List of Message objects

Request Example: /api/messages?conv=id