on develop help sign in
git clone ssh://git.iko.soy/websuck1t

A server example with WebSockets

url: https://websuck1t.herokuapp.com

Methods

GET /posts/all

start with: https://websuck1t.herokuapp.com/posts/all

Use this url to get the token every time when application begins and previous session was closed

Response:

{
    "token": 1828,
    "response": {
        "deleted": [],
        "added": [
            1844,
            1845,
            1846
        ]
    }
}

Response fields

socket.io /posts/subscribe/

NOTE: subscribe to the "postUpdates" event before submitting the token to "subscribeWithToken".

You access the web socket with the socket io protocol. You will most likely need to install a library.

Connecting

To start recieving events you send a "subscribeWithToken" event with a single Int as the messages body. The Int should be the last token you recieved from any API.

Response

After sending the request, you will receive a "subscribeWithToken" event with a single Bool in the message of the event. The Bool indicates whether you have supplied a valid token. If the response is true, you are now subscribed to recieve updates. If thge response was false, nothing happens, you will not be sent any updates.

Receiving updates

Updates will be sent to you on the "postUpdates" event. The event message will contain the following JSON Object (same as /posts/all):

{
    "token": 1828,
    "response": {
        "deleted": [
            1819,
            1835,
            1843
        ],
        "added": [
            1844,
            1845,
            1846
        ]
    }
}

GET /posts/:id

url: https://websuck1t.herokuapp.com/posts/{id}

If there is no post with the given id, the method returns error 404.

Captures:

Response:

{
    "postBody": "This is the post body",
    "postAuthor": 4,
    "postId": 1
}
{
    "postBody": "This is another post body",
    "postAuthor": 4,
    "postId": 1
}
{
    "postBody": "This is the post body",
    "postAuthor": 7,
    "postId": 1
}
{
    "postBody": "This is another post body",
    "postAuthor": 7,
    "postId": 1
}
{
    "postBody": "This is the post body",
    "postAuthor": 92,
    "postId": 1
}

GET /users/:id

url: https://websuck1t.herokuapp.com/users/{id}

Retrieves a user with the given id.

If there is no user with the given id, the method returns error 404.

Captures:

Response:

{
    "secondName": "Leonidovich",
    "firstName": "Seva",
    "userId": 1
}
{
    "secondName": "Barovich",
    "firstName": "Foo",
    "userId": 42
}
{
    "secondName": "Fooovich",
    "firstName": "Bar",
    "userId": 69
}
{
    "secondName": "Quixovich",
    "firstName": "Qux",
    "userId": 8
}