-
-
Notifications
You must be signed in to change notification settings - Fork 18
REST API example
$ curl -d "username=test" -d "password=test" http://localhost:3000/v1/session
{
"err": null,
"status": "success",
"user": {
"id": "ecad21a5-45be-4eb8-9398-db51415992fb",
"username": "test",
"info": {
"screenName": "test",
"email": "[email protected]",
"receiveEmails": "0"
},
"rss": []
}
}
$ curl -d "username=test" -d "password=test" http://localhost:3000/v1/session
{
"err": "user test doesn't exist",
"status": "fail"
}
By default an unauthenticated user is an anonymous user and it cannot edit, delete its posts, comments and personal information, so in the examples below I'm assuming cookie connect.sid is set to a current session. (e.g. -b "cookie.sid=your_cookie_here".)
$ curl -d "username=test" -d "password=test" http://localhost:3000/v1/signup
{
"err": null,
"status": "success",
"user": {
"id": "f6f55f5d-c0b5-4fae-92e8-4d12b84fbe2d",
"username": "test",
"info": {
"screenName": "test"
},
"rss": []
}
}
curl -d "username=test2" -d "password=test" http://localhost:300/v1/signup
{
"err": "user test2 exists",
"status": "fail"
}
$ curl -d "body=test2" http://localhost:3000/v1/posts
{
"id": "237318ed-0c51-4c0a-9be8-2904d3458ce8",
"body": "test2",
"createdAt": 1380397179394,
"updatedAt": 1380397179394,
"comments": [],
"attachments": [],
"likes": [],
"createdBy": {
"id": "0aeb1250-7686-43b6-be15-35b7cede21b4",
"username": "test",
"info": {
"screenName": "test"
},
"rss": []
},
"groups": [
{
"id": "0aeb1250-7686-43b6-be15-35b7cede21b4",
"username": "test",
"info": {
"screenName": "test"
},
"rss": []
}
]
}
$ curl http://localhost:3000/v1/posts/237318ed-0c51-4c0a-9be8-2904d3458ce8
{
"id": "237318ed-0c51-4c0a-9be8-2904d3458ce8",
"body": "test2",
"createdAt": 1380397179394,
"updatedAt": 1380397179395,
"comments": [],
"attachments": [],
"likes": [],
"createdBy": {
"id": "0aeb1250-7686-43b6-be15-35b7cede21b4",
"username": "test3",
"info": {
"screenName": "test3"
},
"rss": []
},
"groups": [
{
"id": "0aeb1250-7686-43b6-be15-35b7cede21b4",
"username": "test3",
"info": {
"screenName": "test3"
},
"rss": []
}
]
}
$ curl -d "body=test" -X PATCH http://localhost:3000/v1/posts/237318ed-0c51-4c0a-9be8-2904d3458ce8
{}
$ curl -X DELETE http://localhost:3000/v1/posts/237318ed-0c51-4c0a-9be8-2904d3458ce8
{}
$ curl -X POST http://localhost:3000/v1/posts/b03fb549-7e49-4c3d-af88-12525ec32984/like
{}
$ curl -X POST http://localhost:3000/v1/posts/b03fb549-7e49-4c3d-af88-12525ec32984/unlike
{}
$ curl -d "postId=b03fb549-7e49-4c3d-af88-12525ec32984" -d "body=comment" http://localhost:3000/v1/comments
{
"id": "c2ce761f-6147-4c1d-b0ad-2c14c89292a1",
"body": "comment",
"postId": "b03fb549-7e49-4c3d-af88-12525ec32984",
"createdAt": 1380397766986,
"updatedAt": 1380397766986,
"createdBy": {
"id": "135b41b3-8193-4612-be7c-38e058a073b6",
"username": "anonymous",
"info": {
"screenName": "anonymous"
},
rss: []
}
}
$ curl -X PATCH -d "body=test" http://localhost:3000/v1/comments/984a2f8f-c0e8-4b15-8f4e-e74d353210fc
{}
$ curl -X DELETE http://localhost:3000/v1/comments/984a2f8f-c0e8-4b15-8f4e-e74d353210fc
{}
$ curl http://localhost:3000/v1/timeline/anonymous
{
"id": "0f8320aa-a31a-4edc-9bab-3643fd92c1ef",
"name": "Posts",
"user": {
"id": "0b1bd0dc-9f10-4002-bcff-3cc7e6e8c02e",
"username": "anonymous",
"type": "user",
"admins": null,
"info": {
"screenName": "anonymous"
},
"statistics": {
"userId": "0b1bd0dc-9f10-4002-bcff-3cc7e6e8c02e",
"posts": "1",
"likes": "0",
"discussions": "0",
"subscribers": "1",
"subscriptions": "1"
},
"subscribers": [
{
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "test"
}
],
"subscriptions": [
{
"id": "e959db46-c2a5-4fee-95be-5f0aed0134a9",
"name": "Posts",
"admins": null,
"user": {
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "test",
"type": "user",
"info": {
"screenName": "test"
}
}
},
{
"id": "9b884493-8ec0-4fc6-8432-946e676aa660",
"name": "Likes",
"user": {
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "test",
"type": "user",
"info": {
"screenName": "test"
}
}
},
{
"id": "4cd94d9e-4f2e-4682-b17f-3b04b6737133",
"name": "Comments",
"user": {
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "test",
"type": "user",
"info": {
"screenName": "test"
}
}
}
]
},
"posts": [
{
"id": "88699b63-48b9-4ca5-b4f8-02909b3f4507",
"body": "Hello world",
"createdAt": 1380398266250,
"updatedAt": 1380398266250,
"comments": [],
"attachments": [],
"likes": [],
"createdBy": {
"id": "0b1bd0dc-9f10-4002-bcff-3cc7e6e8c02e",
"username": "anonymous",
"info": {
"screenName": "anonymous"
},
rss: []
},
"groups": [
{
"id": "0b1bd0dc-9f10-4002-bcff-3cc7e6e8c02e",
"username": "anonymous",
"info": {
"screenName": "anonymous"
},
rss: []
}
]
}
],
"subscribers": [
{
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "test"
}
]
}
{
"name": "River of news",
"id": "cf661652-1256-46a6-a779-f97eac56165f",
"subscribers": [],
"posts": [
{
"id": "0d3833f8-dd9d-4d5c-aad6-7f3d3663a273",
"body": "test3",
"createdAt": 1406020636295,
"updatedAt": 1406020795635,
"attachments": [],
"likes": [],
"createdBy": {
"id": "07bd526c-de3d-4e19-abd3-c94dcac5bd4a",
"username": "test",
"type": "user",
"info": {
"screenName": "test"
},
"rss": []
},
"comments": [
{
"id": "b5ba4bb1-0225-46a8-af33-9c794c70e3c7",
"body": "comment",
"createdAt": 1406020795631,
"updatedAt": 1406020795631,
"postId": "0d3833f8-dd9d-4d5c-aad6-7f3d3663a273",
"createdBy": {
"id": "07bd526c-de3d-4e19-abd3-c94dcac5bd4a",
"username": "test",
"type": "user",
"info": {
"screenName": "test"
},
"rss": []
}
}
],
"groups": [
{
"id": "07bd526c-de3d-4e19-abd3-c94dcac5bd4a",
"username": "test",
"type": "user",
"info": {
"screenName": "test"
},
"rss": []
}
]
},
{
"id": "26e273a0-6759-455a-98b4-7a3da12efe8e",
"body": "40",
"createdAt": 1405545442426,
"updatedAt": 1405545442426,
"attachments": [],
"comments": [],
"likes": [],
"createdBy": {
"id": "fa300d36-1877-42d9-9601-2e582ad9543b",
"username": "anonymous",
"type": "user",
"info": {
"screenName": "anonymous"
},
"rss": []
},
"groups": [
{
"id": "fa300d36-1877-42d9-9601-2e582ad9543b",
"username": "anonymous",
"type": "user",
"info": {
"screenName": "anonymous"
},
"rss": []
}
]
}
],
"user": {
"id": "fa300d36-1877-42d9-9601-2e582ad9543b",
"username": "anonymous",
"type": "user",
"admins": null,
"info": {
"screenName": "anonymous"
},
"subscribers": [],
"statistics": {
"userId": "fa300d36-1877-42d9-9601-2e582ad9543b",
"posts": "41",
"likes": "0",
"discussions": "0",
"subscribers": "0",
"subscriptions": "1"
},
"subscriptions": [
{
"id": "b372e59c-c93b-4362-848b-72e881686505",
"name": "Likes",
"admins": null,
"user": {
"id": "07bd526c-de3d-4e19-abd3-c94dcac5bd4a",
"username": "test",
"type": "user",
"info": {
"screenName": "test"
}
}
},
{
"id": "8b2d19ba-b43a-4293-8152-947f1d46de55",
"name": "Comments",
"admins": null,
"user": {
"id": "07bd526c-de3d-4e19-abd3-c94dcac5bd4a",
"username": "test",
"type": "user",
"info": {
"screenName": "test"
}
}
},
{
"id": "763e84c4-3953-426a-8616-fb6ab0f60b8f",
"name": "Posts",
"admins": null,
"user": {
"id": "07bd526c-de3d-4e19-abd3-c94dcac5bd4a",
"username": "test",
"type": "user",
"info": {
"screenName": "test"
}
}
}
]
},
"postsTimelineId": "0198807f-aa3c-4d75-a80e-d576bae3abdf"
}
### 3. List of subscribers to a timeline
$ curl http://localhost:3000/v1/timeline/0f8320aa-a31a-4edc-9b-3643fd92c1ef/subscribers [ { "id": "fa7d253f-7a70-452f-924b-bda7953a5321", "username": "test", "info": { "screenName": "test" }, "admins": null } ]
### 4. Subscribe to a timeline
curl -X POST http://localhost:3000/v1/timeline/e959db46-c2a5-4fee-95be-5f0aed0134a9/subscribe { "err": null, "status": "success" }
### 5. Unsubscribe to a timeline
curl -X POST http://localhost:3000/v1/timeline/e959db46-c2a5-4fee-95be-5f0aed0134a9/unsubscribe { "err": null, "status": "success" }
Users and groups
----------------
### 1. Get current user info
$ curl http://localhost:3000/v1/whoami { "id": "0b1bd0dc-9f10-4002-bcff-3cc7e6e8c02e", "username": "anonymous", "type": "user", "info": { "screenName": "anonymous" }, "rss": [] }
### 2. Get user info
$ curl http://localhost:3000/v1/users/0b1bd0dc-9f10-4002-bcff-cc7e6e8c02e { "id": "0b1bd0dc-9f10-4002-bcff-3cc7e6e8c02e", "username": "anonymous", "type": "user", "info": { "screenName": "anonymous" }, "rss": [] }
### 3. Get user subscriptions
$ curl http://localhost:3000/v1/users/anonymous/subscriptions [ { "id": "e959db46-c2a5-4fee-95be-5f0aed0134a9", "name": "Posts", "admins": null, "user": { "id": "fa7d253f-7a70-452f-924b-bda7953a5321", "username": "test", "type": "user", "info": { "screenName": "test" } } }, { "id": "9b884493-8ec0-4fc6-8432-946e676aa660", "name": "Likes", "admins": null, "user": { "id": "fa7d253f-7a70-452f-924b-bda7953a5321", "username": "test", "type": "user", "info": { "screenName": "test" } } }, { "id": "4cd94d9e-4f2e-4682-b17f-3b04b6737133", "name": "Comments", "admins": null, "user": { "id": "fa7d253f-7a70-452f-924b-bda7953a5321", "username": "test", "type": "user", "info": { "screenName": "test" } } } ]
### 4. Get user's subscribers
$ curl http://localhost:3000/v1/users/anonymous/subscribers { "subscribers": [ { "id": "fa7d253f-7a70-452f-924b-bda7953a5321", "username": "test", "info": { "screenName": "test" } } ] }
### 5. Unsubscribe user from a user or a group
$ curl -X DELETE http://localhost:3000/v1/users/anonymous/subscribers/fa7d253f-7a70-452f-924b-bda7953a5321 { "err": null, "status": "success" }
### 6. Give user group admin righs
$ curl -X POST http://localhost:3000/v1/users/group/subscribers/fa7d253f-7a70-452f-924b-bda7953a5321/admin { "err": null, "status": "success" }
### 7. Remove admin rights
$ curl -X POST http://localhost:3000/v1/users/group/subscribers/fa7d253f-7a70-452f-924b-bda7953a5321/unadmin { "err": null, "status": "success" }
### 8. Delete group (users for the time being are permanent)
$ curl -X DELETE http://localhost:3000/v1/users/2f4d64f5-5c3a-4dfd-8a16-fd894e9aa9a5 { "err": null, "status": "success" }
### 9. Update user info
$ curl -X PATCH -d "params[email]=[email protected]" -d "params[screenName]=newTest" -d "params[receiveEmails]=1" -d "params[rss[]]=http://rss" -d "params[userId]=fa7d253f-7a70-452f-924b-bda7953a5321" http://localhost:3000/v1/users { "id": "fa7d253f-7a70-452f-924b-bda7953a5321", "username": "test", "type": "user", "info": { "screenName": "test", "email": "[email protected]", "receiveEmails": "1" }, "rss": [ "http://rss" ] }
Stats
-----
### 1. Get top users who likes more than other
$ curl http://localhost:3000/v1/top/likes [ { "id": "fa7d253f-7a70-452f-924b-bda7953a5321", "username": "test", "info": { "screenName": "test", "email": "[email protected]", "receiveEmails": "0" }, "rss": [], "score": "0" }, { "id": "0b1bd0dc-9f10-4002-bcff-3cc7e6e8c02e", "username": "anonymous", "info": { "screenName": "anonymous" }, "rss": [], "score": "0" } ]
Tags
----
### 1. Get tags sorted by frequency
$ curl http://localhost:3000/v1/tags [ "#world", "#hello" ]
Search
------
### 1. Simple search by a keyword
$ curl http://localhost:3000/v1/search/hel { "posts": [ { "id": "88699b63-48b9-4ca5-b4f8-02909b3f4507", "body": "Hello world", "createdAt": 1380398266250, "updatedAt": 1380398266250, "groups": [], "comments": [], "attachments": [], "likes": [], "createdBy": { "id": "0b1bd0dc-9f10-4002-bcff-3cc7e6e8c02e", "username": "anonymous", "info": { "screenName": "anonymous" } } }, { "id": "4163f133-a580-4bbf-a59e-97825e3762fa", "body": "#hello", "createdAt": 1380400485640, "updatedAt": 1380400485641, "groups": [], "comments": [], "attachments": [], "likes": [], "createdBy": { "id": "fa7d253f-7a70-452f-924b-bda7953a5321", "username": "test", "info": { "screenName": "test", "email": "[email protected]", "receiveEmails": "0" } } } ] }