-
-
Notifications
You must be signed in to change notification settings - Fork 18
REST API example
epicmonkey edited this page Sep 28, 2013
·
27 revisions
- Authentication
$ 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"
}
}
}
- Registration
$ 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"
}
}
}
By default unauthenticated user is anonymous user and he cannot edit or delete his posts or comments, 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".)
- Create new post
$ 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"
}
},
"groups": [
{
"id": "0aeb1250-7686-43b6-be15-35b7cede21b4",
"username": "test",
"info": {
"screenName": "test"
}
}
]
}
- Read post
$ 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"
}
},
"groups": [
{
"id": "0aeb1250-7686-43b6-be15-35b7cede21b4",
"username": "test3",
"info": {
"screenName": "test3"
}
}
]
}
- Update post
$ curl -d "body=test" -X PATCH http://localhost:3000/v1/posts/237318ed-0c51-4c0a-9be8-2904d3458ce8
{}
- Delete post
$ curl -X DELETE http://localhost:3000/v1/posts/237318ed-0c51-4c0a-9be8-2904d3458ce8
{}
- Like post
$ curl -X POST http://localhost:3000/v1/posts/b03fb549-7e49-4c3d-af88-12525ec32984/like
{}
- Unlike post
$ curl -X POST http://localhost:3000/v1/posts/b03fb549-7e49-4c3d-af88-12525ec32984/unlike
{}
- Add new comment
$ 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"
}
}
}
- Update comment
$ curl -X PATCH -d "body=test" http://localhost:3000/v1/comments/984a2f8f-c0e8-4b15-8f4e-e74d353210fc
{}
- Delete comment
$ curl -X DELETE http://localhost:3000/v1/comments/984a2f8f-c0e8-4b15-8f4e-e74d353210fc
{}
- Get user timeline
$ 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",
"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",
"user": {
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "test"
}
},
{
"id": "9b884493-8ec0-4fc6-8432-946e676aa660",
"name": "Likes",
"user": {
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "test"
}
},
{
"id": "4cd94d9e-4f2e-4682-b17f-3b04b6737133",
"name": "Comments",
"user": {
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "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"
}
},
"groups": [
{
"id": "0b1bd0dc-9f10-4002-bcff-3cc7e6e8c02e",
"username": "anonymous",
"info": {
"screenName": "anonymous"
}
}
]
}
],
"subscribers": [
{
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "test"
}
]
}
- 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"
}
}
]
- Subscribe to a timeline
curl -X POST http://localhost:3000/v1/timeline/e959db46-c2a5-4fee-95be-5f0aed0134a9/subscribe
{
"err": null,
"status": "success"
}
- Unsubscribe to a timeline
curl -X POST http://localhost:3000/v1/timeline/e959db46-c2a5-4fee-95be-5f0aed0134a9/unsubscribe
{
"err": null,
"status": "success"
}
- Get current user info
$ curl http://localhost:3000/v1/whoami
{
"id": "0b1bd0dc-9f10-4002-bcff-3cc7e6e8c02e",
"username": "anonymous",
"type": "user",
"info": {
"screenName": "anonymous"
},
"rss": []
}
- 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": []
}
- Get user subscriptions
$ curl http://localhost:3000/v1/users/anonymous/subscriptions
[
{
"id": "e959db46-c2a5-4fee-95be-5f0aed0134a9",
"name": "Posts",
"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"
}
}
}
]
- Get user's subscribers
$ curl http://localhost:3000/v1/users/anonymous/subscribers
{
"subscribers": [
{
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "test",
"info": {
"screenName": "test"
}
}
]
}
- 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"
}
- 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"
}
- Remove admin rights
$ curl -X POST http://localhost:3000/v1/users/group/subscribers/fa7d253f-7a70-452f-924b-bda7953a5321/unadmin
{
"err": null,
"status": "success"
}
- 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"
}
- Update user info
$ curl -X PATCH -d "email=[email protected]" -d "screenName=newTest" -d "receiveEmails=1" -d "rss[]=http://rss" http://localhost:3000/v1/users/fa7d253f-7a70-452f-924b-bda7953a5321 { "id": "fa7d253f-7a70-452f-924b-bda7953a5321", "username": "test", "type": "user", "info": { "screenName": "test", "email": "[email protected]", "receiveEmails": "1" }, "rss": [ "http://rss" ] }