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

Post

  1. Create new post
curl -b "connect.sid=s%3A2H%2FlKW2M%2BC1qsjkwuIOrfL2q.WtQIfmnzNYqVfsfR2opIM5CeDg3y1%2FQNy7nCwJsT14" -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 -b "connect.sid=s%3A2H%2FlKW2M%2BC1qsjkwuIOrfL2q.WtQIfmenzNYqVfsfR2opIM5CeDg3y1%2FQNy7nCwJsT14" -d "body=test" -X PATCH http://localhost:3000/v1/posts/237318ed-0c51-4c0a-9be8-2904d3458ce8
{}
  1. Delete post
curl -b "connect.sid=s%3A2H%2FlKW2M%2BC1qsjkwuIOrfL2q.WtQIfmenzNYqVfsfR2opIM5CeDg3y1%2FQNy7nCwJsT14" -X DELETE http://localhost:3000/v1/posts/237318ed-0c51-4c0a-9be8-2904d3458ce8
{}
Clone this wiki locally