-
-
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
{}