Challenge Overview
A previous challenge has implemented a set of REST APIs for handling video assets, including storing them and managing them (create, retrieve, update, delete). This challenge will expand the REST API a bit to allow for pagination and some additional fields. It will also define some basic load testing documentation targeting loader.io.
Existing API
The existing Node application and deployment details are in Gitlab, and the URL to the repository can be found in the forum.
Pagination
When searching or retrieving data, we want to allow the caller to paginate the results. As we add more and more videos, this is an important feature. To support this, we will make the following changes:
1. Add a pageSize and pageIndex value to the /videos GET path to allow for arbitrary page sizes. The page index will be the 0-based index of the page to retrieve. If neither value is provided, we will return all records. If just pageSize is provided, we will assume pageIndex will default to 0.
2. To support smart pagination in the UI, we need to know how many videos are available in the backend, what the page size is, and what page we are on. To do this, we can add a few additional fields to the JSON reponse:
* Change the response to include "totalVideosCount", "pageSize", and "pageIndex" values
* Move the current array to a field called "videos", which will be the array of video records being returned.
Return a 400 error if the pageSize or pageIndex are out of bounds for the videos in the data set.
Sorting
To support additional UI features, we would like to be able to sort the video results. For instance, we might want to sort by publish date descending, instead of just by when the videos were added to the data store.
We will add two new fields to the REST /videos GET request:
* sortField, which is the video field to sort on
* sortDirection (ASC or DESC) to indicate which direction to sort
The sort field should be able to be used in conjunction with the result of the filtering and pagination parameters.
Return a 400 error if the sortField value doesn't match any known video fields
Return a 400 error if sortDirection is not "ASC" or "DESC"
If sortDirection isn't provided, assume "DESC".
Subcategory
To allow for more filtering on the videos, we are going to add a "subcategory" field to the video object. This will be a string value that will allow us to sort and display videos with a little more metadata information. For instance, we have "News" and "Lifestyle" as current categories in the data set. With a sub-category, we will be able to not only split out News from Lifestyle, but we will be able to categorize further for things like "News / Politics" vs. "News / Breaking News" or "Lifestyle / Food" vs. "Lifestyle / Decorating".
Retrieve by category and sub category
In addition to adding the sub-category field, we will add new REST endpoints to retrieve videos by category or sub-category. We will add a new "subcategory" parameter to the /videos endpoint so the caller could conceivably request "News / Politics" videos. If no sub-category is provided, just the main category value will be used. If the subcategory is provided but no category is given, return a 400 error.
Retrieve all category information
In an effort to aid the UI, we will add a new "/categories" endpoint that returns the unique category and sub-category information in the data set. It will just return category names and the subcategories underneath each category name. This will be used in the UI to quickly show menu information.
Swagger file
The swagger file must be kept up to date and match the changes above.
Loader.io documentation
To aid in load testing the solution, please submit a separate markdown file that documents how to set up some loader.io tests for the REST API. We want to load test the POST and GET to the /videos enpoint (including various permutations of the filters, sorting, and pagination).
Heroku deploy
Make sure the Heroku deployment information is up-to-date and that you keep the package.json up to date as well. Don't expect the deployment to be anything other than "npm install" / "npm start" locally and "git push heroku master" for Heroku deployment.
Existing API
The existing Node application and deployment details are in Gitlab, and the URL to the repository can be found in the forum.
Pagination
When searching or retrieving data, we want to allow the caller to paginate the results. As we add more and more videos, this is an important feature. To support this, we will make the following changes:
1. Add a pageSize and pageIndex value to the /videos GET path to allow for arbitrary page sizes. The page index will be the 0-based index of the page to retrieve. If neither value is provided, we will return all records. If just pageSize is provided, we will assume pageIndex will default to 0.
2. To support smart pagination in the UI, we need to know how many videos are available in the backend, what the page size is, and what page we are on. To do this, we can add a few additional fields to the JSON reponse:
* Change the response to include "totalVideosCount", "pageSize", and "pageIndex" values
* Move the current array to a field called "videos", which will be the array of video records being returned.
Return a 400 error if the pageSize or pageIndex are out of bounds for the videos in the data set.
Sorting
To support additional UI features, we would like to be able to sort the video results. For instance, we might want to sort by publish date descending, instead of just by when the videos were added to the data store.
We will add two new fields to the REST /videos GET request:
* sortField, which is the video field to sort on
* sortDirection (ASC or DESC) to indicate which direction to sort
The sort field should be able to be used in conjunction with the result of the filtering and pagination parameters.
Return a 400 error if the sortField value doesn't match any known video fields
Return a 400 error if sortDirection is not "ASC" or "DESC"
If sortDirection isn't provided, assume "DESC".
Subcategory
To allow for more filtering on the videos, we are going to add a "subcategory" field to the video object. This will be a string value that will allow us to sort and display videos with a little more metadata information. For instance, we have "News" and "Lifestyle" as current categories in the data set. With a sub-category, we will be able to not only split out News from Lifestyle, but we will be able to categorize further for things like "News / Politics" vs. "News / Breaking News" or "Lifestyle / Food" vs. "Lifestyle / Decorating".
Retrieve by category and sub category
In addition to adding the sub-category field, we will add new REST endpoints to retrieve videos by category or sub-category. We will add a new "subcategory" parameter to the /videos endpoint so the caller could conceivably request "News / Politics" videos. If no sub-category is provided, just the main category value will be used. If the subcategory is provided but no category is given, return a 400 error.
Retrieve all category information
In an effort to aid the UI, we will add a new "/categories" endpoint that returns the unique category and sub-category information in the data set. It will just return category names and the subcategories underneath each category name. This will be used in the UI to quickly show menu information.
Swagger file
The swagger file must be kept up to date and match the changes above.
Loader.io documentation
To aid in load testing the solution, please submit a separate markdown file that documents how to set up some loader.io tests for the REST API. We want to load test the POST and GET to the /videos enpoint (including various permutations of the filters, sorting, and pagination).
Heroku deploy
Make sure the Heroku deployment information is up-to-date and that you keep the package.json up to date as well. Don't expect the deployment to be anything other than "npm install" / "npm start" locally and "git push heroku master" for Heroku deployment.
Submission format
Your submission should be provided as a Git patch file against commit hash 344a60a8a9e9428b2a0ff5300a0853d4f7eb43a3. MAKE SURE TO TEST YOUR PATCH FILE!