Skip to content
jabbrass edited this page Sep 4, 2014 · 1 revision

REST API


Adding a new collection

POST to /collection

Expect JSON data:

{ title: title, collection_url: urlOnOurSite***, description: description, user: user, links: [ { url: url, title: title, description: description }, ... ] }

*** urlOnOurSite must be in the form of '/user/[username]/[collectionName]'


If successful:

Returns JSON object of Collection: { "id": collectionID, "u_id": userID, "title":title, "collection_url": urlOfTheCollection, "description":description, "stars":0 (this is default value), "created_at": timeOfCreationOfTheEntry }

If error:

Return Error Message: "Cannot create collection"


Example

Post to: http://localhost:3000/collection

JSON Data sent:

'{"title":"new Collection","url":"/user/test4/new-collection5","description":"great collection","user":"Test4","links":[{"url":"http://google.com","title":"google","description":"a site that google owns"}]}'

JSON returned

{"id":13, "u_id":17,"title":"new Collection","collection_url":"/user/test4/new-collection5","description":"great collection","stars":0,"updated_at":"2014-09-03T01:08:52.045Z","created_at":"2014-09-03T01:08:52.045Z"}


Updating a collection

POST to /collection/:collectionID


Expected JSON data:

General form:

{title: newTitle, description: newDescription, links: [ { url: newLinkUrl, title: newLinkTitle, description: newLinkDescription }, ... ] }


Note: All properties on the above JSON object are optional. Only include the properties which need to be updated for the collection.


Updateable Collection Details and property required on the JSON data object:

  1. Collection Title: {title: newCollectionTitle, ...},
  2. Collection Description: {..., description: newCollectionDescription, ...}
  3. Create a new link in the collection: {..., links: [{url: newLinkUrl, description: newLinkDescription, title: newUrlTitle},...]}
  4. Update existing link in the collection: {..., links: [{url: oldLinkUrl, description: newLinkDescription, title: newUrlTitle },...]}

Note: stars, collection_url, collection_id cannot be updated.


Data returned:

If success:

Returns JSON object of the collection:

{"id": colllectionID, "title": newCollectionTitle, "description": newCollectionDescription,"updated_at": timeOfUpdate }

If error: Cannot update collection


Example

POST TO: http://localhost:3000/collection/13

JSON data expected by Server:

'{"title":"new Collection","url":"/user/test4/new-collection5","description":"CHANGED DESCRIPTION","links":[{"url":"http://google.com","title":"NEW link title","description":"a site that google owns"}]}'


JSON data returned by Server:

{"id":"13","title":"new Collection","description":"CHANGED DESCRIPTION","updated_at":"2014-09-03T01:47:21.102Z"}


Retrieving a particular collection

Through the REST API:
GET to user/:user/:collection

Expected JSON data: None


Data returned

If success, returns a JSON representation of the collection:
Data: {c_id: collectionID, title: title, url: urlOnOurSite, description: description, user: user, stars: stars, links: [ { id: linkID, c_id: collectionIDToWhichTheLinkBelongs, link_url: url, link_title: title, description: linkDescription, created_at: timeOfCreation, updated_at: timeOfUpdate }, ... ] }


If error, returns 404 and "Cannot find this collection"


Example

GET to http://localhost:3000/user/test4/new-collection5


JSON data that is returned:


{"c_id":13,"title":"new Collection","url":"/user/test4/new-collection5","description":"CHANGED DESCRIPTION","user":"test4","stars":0,"links":

[{"id":15,"c_id":13,"link_url":"http://google.com","link_title":"NEW link title","description":"a site that google owns","click_count":0,"created_at":"2014-09-03T01:08:52.000Z","updated_at":"2014-09-03T01:47:21.000Z"}]}



Retrieve all collection titles, descriptions and url's

GET to /all

Expected data to send to server: none


Returned Data

On success, returns a JSON object:
Data: { collections: [ {id: collectionID, title: collectionTitle, collection_url: urlOnOurSite, description: description, username: username}, {}, {} ...] }


On error, returns 404 Status with message "Cannot find all collections"


Example:


GET request to http://localhost:3000/all


{"collections":[{"id":1,"title":"Collection Test Title","collection_url":"http://localhost:3000/collection","stars":0,"description":"Collection Description","username":"Test"},
... {"id":13,"title":"new Collection","collection_url":"/user/test4/new-collection5","stars":0,"description":"CHANGED DESCRIPTION","username":"Test4"}]}

Add a particular user

POST to /user

Expected Json Data:

{username:username,password:password,githubHandle:githubHandle,email:email}

Returns

If successful: user_id

If failure(if username or githubHandle or email are already in use): "User already exists"

Example:

Post to http://curates.azurewebsites.net/user

Expected Json data:

'{"username": "Joe", "password":"123", "githubHandle":"joegithub", "email":"[email protected]"}'

If success, return 10

If failure, return "User already exists"

Retrieve a particular user with his/her collections

GET to /user/:user
Expected data: none
Returns

If success:

Return a JSON representation of the user and all collections owned by this user.

Returned Data:

{username:username, githubHandle:githubHandle, email:email,
collections:[{c_id:collection_id, title:title, url:urlOnOurSite, description:description, user:user},{},{}...]}

If failure:

Returnes string: "User doesn't exist"

Example:

Get to http://curates.azurewebsites.net/user/Joe

Expected data: none

Returned Json data:

If success:

'{"username":"Joe","githubHandle":"JoeHandle","email": "[email protected]",
"collections":[{"c_id": "1", "title": "Angular collection", "url": "www.angular.com", "description": "angular is awesome", "user": "Joe"}]}'

If failure:

Returnes string: "User doesn't exist"

Update a particular user profile

We haven't implemented it yet.
POST to /user/:user
Expected Data:

{username:username, password:password, githubHandle:githubHandle, email: email}

Return ____if successful or ___ if user doesn't exist.
Example:

Post to http://curates.azurewebsites.net/user/Joe

Expected data:

'{"username":"Joe","password":"123","githubHandle":"joeHandle", "email": "[email protected]"}'

Returned:

If success: ___

If failure: ___