Skip to content

REST API example

epicmonkey edited this page Sep 28, 2013 · 27 revisions

Sessions

  1. 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"
    }
  }
}
  1. 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, however in the examples below I'm assuming cookie connect.sid is set to a current session. (-b "cookie.sid=your_cookie_here").

Post

  1. 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"
      }
    }
  ]
}
  1. 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"
      }
    }
  ]
}
  1. Update post
$ curl -d "body=test" -X PATCH http://localhost:3000/v1/posts/237318ed-0c51-4c0a-9be8-2904d3458ce8
{}
  1. Delete post
$ curl -X DELETE http://localhost:3000/v1/posts/237318ed-0c51-4c0a-9be8-2904d3458ce8
{}
  1. Like post
$ curl -X POST http://localhost:3000/v1/posts/b03fb549-7e49-4c3d-af88-12525ec32984/like
{}
  1. Unlike post
$ curl -X POST http://localhost:3000/v1/posts/b03fb549-7e49-4c3d-af88-12525ec32984/unlike
{}

Comments

  1. 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"
    }
  }
}
Clone this wiki locally