The Basic Goal : Create an API for a task management / todo list.
The Fun Goal : Imagine your hot new startup, Llama.io, is creating the best todo webapp on the market. You're competing in a crowded space with hot players like Asana, Wunderlist, Google Keep, etc, so your API has to be top-notch.
Implement an API with the following end-points (they would be preceded by something like http://localhost:4000/api/). Your implementation should use Node, Express and Mongoose.
Endpoints | Actions | Intended Outcome |
---|---|---|
users | GET | Respond with a List of users |
POST | Create a new user. Respond with details of new user | |
users/:id | GET | Respond with details of specified user or 404 error |
PUT | Replace entire user with supplied user or 404 error | |
DELETE | Delete specified user or 404 error | |
tasks | GET | Respond with a List of tasks |
POST | Create a new task. Respond with details of new task | |
tasks/:id | GET | Respond with details of specified task or 404 error |
PUT | Replace entire task with supplied task or 404 error | |
DELETE | Delete specified user or 404 error |
NOTE: In addition, the API has the following JSON encoded query string parameters for the GET requests to the users
and tasks
endpoints. You will also need to make sure the [+select+] parameter works for the users/:id
and tasks/:id
endpoints.:
Parameter | Description |
---|---|
where | filter results based on JSON query |
sort | specify the order in which to sort each specified field (1- ascending; -1 - descending) |
select | specify the set of fields to include or exclude in each document (1 - include; 0 - exclude) |
skip | specify the number of results to skip in the result set; useful for pagination |
limit | specify the number of results to return (default should be 100 for tasks and unlimited for users) |
count | if set to true, return the count of documents that match the query (instead of the documents themselves) |
Here are some example queries and what they would return:
Query | Description |
---|---|
http://localhost:4000/api/tasks |
Returns full list of tasks |
http://localhost:4000/api/users |
Returns full list of users |
http://localhost:4000/api/users?where={"_id": "55099652e5993a350458b7b7"} |
Returns a list with a single user with the specified ID ('_id' will be different) |
http://localhost:4000/api/tasks?where={"completed": true} |
Returns a list of completed tasks |
http://localhost:4000/api/tasks?where={"_id": {"$in": ["59f930d6b1596b0cb3e82953","5a1b6d7bd72ba9106fe9239c"]}} |
Returns a set of tasks |
http://localhost:4000/api/users?sort={"name": 1} |
Returns a list of users sorted by name |
http://localhost:4000/api/users?select={"_id": 0} |
Returns a list of users without the _id field |
http://localhost:4000/api/tasks?skip=60&limit=20 |
Returns tasks number from 61 to 80 |
The API should be able to handle any combination of those parameters in a single request. For example, the following is a valid GET request:
http://localhost:4000/api/users?sort={"name": 1}&skip=60&limit=20
Here is the User Schema:
- "name" - String
- "email" - String
- "pendingTasks" - [String] - The _id fields of the pending tasks that this user has
- "dateCreated" - Date - should be set automatically by server
Here is the Task Schema:
- "name" - String
- "description" - String
- "deadline" - Date
- "completed" - Boolean
- "assignedUser" - String - The _id field of the user this task is assigned to - default ""
- "assignedUserName" - String - The name field of the user this task is assigned to - default "unassigned"
- "dateCreated" - Date - should be set automatically by server to present date
We assume that each task can be assigned only to one user.
-
Your database should be on MongoDB Atlas. It should contain at least 20 users and 100 tasks (about half of which should be completed) (We provided scripts for you in the database_scripts folder. Read below how to use these scripts). NOTE: Please add "Allow access from anywhere" to your cluster in the IP Whitelist" (This is usually not a good practice in real use. Here is just easier for us to grade your mp)
-
Responses from your API should be a JSON object with two fields. The first field should be named
message
and should contain a human readable String. The second field should be nameddata
and should contain the actual JSON response object. For example, here is a valid response:
{
"message": "OK",
"data": {
"_id": "55099652e5993a350458b7b7",
"email": "[email protected]",
"name": "Sujay Khandekar"
}
}
-
Error responses from your API should also also be a JSON object with a
message
anddata
fields. Messages have to sensible and human readable so that on the client side it can be displayed to the user. Also, it should be independent of the server side technology that you are using. For example, your API should not return an error message directly from Mongoose to the client. For examples of error messages, take a look at the API reference implementation that we have provided. -
Your API should respond with appropriate HTTP status codes for both successful and error responses. You should at least have the following codes: 200 (success), 201 (created), 404 (not found), 500 (server error).
-
You should implement the query string functionality by using the methods provided by Mongoose (as opposed to querying Mongoose for all the results and then doing the filtering/sorting/skipping etc. in your Node/Express application code).
-
Have server side validation for:
- Users cannot be created (or updated) without a name or email. All other fields that the user did not specify should be set to reasonable values.
- Multiple users with the same email cannot exist.
- Tasks cannot be created (or updated) without a name or a deadline. All other fields that the user did not specify should be set to reasonable values.