-
-
Notifications
You must be signed in to change notification settings - Fork 18
REST API example
epicmonkey edited this page Dec 6, 2013
·
27 revisions
$ 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"
}
}
}
$ 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 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 "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"
}
}
]
}
$ 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"
}
}
]
}
$ 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"
}
}
}
$ 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",
"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"
}
]
}
$ curl http://localhost:3000/v1/timeline/0f8320aa-a31a-4edc-9b-3643fd92c1ef/subscribers
[
{
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "test",
"info": {
"screenName": "test"
}
}
]
curl -X POST http://localhost:3000/v1/timeline/e959db46-c2a5-4fee-95be-5f0aed0134a9/subscribe
{
"err": null,
"status": "success"
}
curl -X POST http://localhost:3000/v1/timeline/e959db46-c2a5-4fee-95be-5f0aed0134a9/unsubscribe
{
"err": null,
"status": "success"
}
$ curl http://localhost:3000/v1/whoami
{
"id": "0b1bd0dc-9f10-4002-bcff-3cc7e6e8c02e",
"username": "anonymous",
"type": "user",
"info": {
"screenName": "anonymous"
},
"rss": []
}
$ 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": []
}
$ 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"
}
}
}
]
$ curl http://localhost:3000/v1/users/anonymous/subscribers
{
"subscribers": [
{
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "test",
"info": {
"screenName": "test"
}
}
]
}
$ curl -X DELETE http://localhost:3000/v1/users/anonymous/subscribers/fa7d253f-7a70-452f-924b-bda7953a5321
{
"err": null,
"status": "success"
}
$ curl -X POST http://localhost:3000/v1/users/group/subscribers/fa7d253f-7a70-452f-924b-bda7953a5321/admin
{
"err": null,
"status": "success"
}
$ curl -X POST http://localhost:3000/v1/users/group/subscribers/fa7d253f-7a70-452f-924b-bda7953a5321/unadmin
{
"err": null,
"status": "success"
}
$ curl -X DELETE http://localhost:3000/v1/users/2f4d64f5-5c3a-4dfd-8a16-fd894e9aa9a5
{
"err": null,
"status": "success"
}
$ curl -X PATCH -d "[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"
]
}
$ curl http://localhost:3000/v1/top/likes
[
{
"id": "fa7d253f-7a70-452f-924b-bda7953a5321",
"username": "test",
"info": {
"screenName": "test",
"email": "[email protected]",
"receiveEmails": "0"
},
"score": "0"
},
{
"id": "0b1bd0dc-9f10-4002-bcff-3cc7e6e8c02e",
"username": "anonymous",
"info": {
"screenName": "anonymous"
},
"score": "0"
}
]
$ curl http://localhost:3000/v1/tags
[
"#world",
"#hello"
]
$ $ 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"
}
}
}
]
}