Experimental Node.js server app exposing a RESTful API for uploading own photos and voting for other users´ photos.
Install Node.js see http://nodejs.org/
Install MongoDB see https://www.mongodb.org/
Install project dependencies:
$ npm install
Run database:
$ mongod
Run server (Default port is 3000):
$ node app.js
All resources have _id
as ID attribute.
The application enforces user registration. All subsequent API calls require authentication using HTTP Basic authentication.
POST /api/users
{email: [String (required)], password: [String (required)], gender: [enum: ['male', 'female'] (required)]}
201, {_id: [String], email: [String], gender: [enum: ['male', 'female']}
409, {message: 'Email already registered'}
$ curl -d '{"email":"hello@example.org","password":"qwerty","gender":"male"}' -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST http://127.0.0.1:3000/api/users
Users may create and upload photos. An array of created photo IDs are provided when later creating a contact sheet.
POST /api/photos
{photo: [binary image file data]}
201, {_id: [String], path: [String], userId: [String], displayCount: [Number], likedBy: [Array(String)]}
404, {message: 'User not found'}
400, {message: 'Missing photo'}
$ curl -F photo="@/local/path/to/photo.jpg" -i -H "Accept applciation/json" -X POST http://hello%40example.org:qwerty@127.0.0.1:3000/api/photos
The contact sheet holds a collection of photos, and keeps track of how many other photos the user has voted for (liked).
POST /api/sheets
{photoIds: [Array(String)]}
201, {_id: [String], userId: [String], voteCount: [Number], photos: [Array(Photo)]}
404, {message: 'User not found'}
400, {message: 'Missing photos'}
400, {message: 'Minimum of X photos must be provided'}
$ curl -d '{"photoIds":["5352a2133fad13b40bdd64b1","5352bf963fad13b40bdd64b2"]}' -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST http://hello%40example.org:qwerty@127.0.0.1:3000/api/sheets
The user can access a list of random photos of other users. Two photos are returned by default.
GET /api/photos?count=4
200, [{_id: [String], path: [String], userId: [String], displayCount: [Number], likedBy: [Array(String]}, ...]
$ curl -i -H "Accept: application/json" http://hello%40example.org:qwerty@127.0.0.1:3000/api/photos
In the context of a Contact Sheet the user can like other users´ photos. The response indicates how many photos the user needs to like before getting access to likes for own photos.
POST /api/sheets/:id/likes
{photoId: [String]}
200, {votesLeft: [Number]}
404, {message: 'User not found'}
404, {message: 'Sheet not found'}
403, {message: 'Permission to sheet denied'
404, {message: 'Photo not found'}
400, {message: 'Photo already liked by user'}
$ curl -d '{"_id":"5350eb54f9d135080453428b"}' -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST http://hello%40example.org:qwerty@127.0.0.1:3000/api/sheets/5352c844463671180ee586ae/likes
Returns results for photos in own contact sheet or empty content if user has not liked enough of other users´ photos.
GET /api/sheets/:id/likes
304
200, [{_id: [Number], path: [String], userId: [String], displayCount: [Number], likedBy: [Array(String]}]
404, {message: 'User not found'}
404, {message: 'Sheet not found'}
403, {message: 'Permission denied'}
curl -i -H "Accept: application/json" http://hello%40example.org:qwerty@127.0.0.1:3000/api/sheets/5352c844463671180ee586ae/likes
The client should store user credentials needed to authenticate. The client should also store the ID for its current contact sheet.