-
Notifications
You must be signed in to change notification settings - Fork 16
SQL REST API
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]'
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 }
Return Error Message: "Cannot create collection"
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"}
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:
- Collection Title: {title: newCollectionTitle, ...},
- Collection Description: {..., description: newCollectionDescription, ...}
- Create a new link in the collection: {..., links: [{url: newLinkUrl, description: newLinkDescription, title: newUrlTitle},...]}
- Update existing link in the collection: {..., links: [{url: oldLinkUrl, description: newLinkDescription, title: newUrlTitle },...]}
Note: stars, collection_url, collection_id cannot be updated.
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/13JSON 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"}
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"}]}
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"}]}
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"
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"
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"
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"
{username:username, password:password, githubHandle:githubHandle, email: email}
Post to http://curates.azurewebsites.net/user/Joe
Expected data:
'{"username":"Joe","password":"123","githubHandle":"joeHandle", "email": "[email protected]"}'
Returned:
If success: ___
If failure: ___