ASP.Net simple inventory system with REST API
-
Download to local repository
-
Open with Visual Studio (Used VS 2015 to create it)
-
Run with Chrome (or other) browser to see simple web test page, or
-
Run unit tests.
This simple demo application was created using Visual Studio 2015 using
GET api/inventory - returns all items in the inventory
GET api/inventory/{label} - get a specific inventory item by label if it exists
POST api/inventory/{item} - add an item to the inventory by {item}. Item should contain these field : (string)label, (DateTime)expiration, (string)type.
DELETE api/inventory/{label} - remove an item from inventory if it exists.
The design was implemented through Visual Studio, selecting a ASP Web API project type, and then and empty project. I choose empty project so as to eliminate all the extra files generated by the system, and just show my work. I then created directories for "Models", "Controllers", and "Service" so as to keep the core files neatly organized. This project roughly follows the MVC pattern, minus the views since it is purely an API provider. The service directory holds the code for the automatic data expiration system, that unlike the api code, is initiated at startup and runs continously. The Models directory holds data related files. The controller directory holds the one controller file that supports the inventory api methods.
The inventory data is held in a local repository which is implemented as a singleton class so that all users plus the expiration task can have access to the exact same data set. All methods for getting, adding, or removing data are protected by a thread locking mechanism to prevent data corruption due to simultaneous access.
The automatic data expiring service runs in its own thread, and wakes up once a second to check for expired data.
The unit tests were implemented in their own directory, separate from the main project code, as is standard practice for code and test separation/organization. There is a separate unit test file for each of the API methods. The unit test cover just the basic, positive test cases at this time. This was a trade-off for time to complete this demo project.
-
Inventory items are only specified by their "label" attribute.
-
There is no implementation of inventory count for a particular item. Adding a new item with the same label as an existing item will over-write the exisiting item. Removing a particular item removes the one and only item with this label.
-
The system does not implement Authorization or Authentication at this time. Anyone can access, add, or remove any item.
-
The mechanism for automatically removing expired items runs as a separate, stand-alone thread. This thread wakes-up every second to check the inventory for expired items. If an item has expired, it is removed from the data store, and a debug console message is displayed for notification. This 'expiring' mechanism does not take into account how many items are in the inventory so it could potentialy take a significant amount of time and resources to run if the data store contained a large amount of items. Ideally this mechanism would have built-in throttling so that it would not tie-up computer resources and the data repository.
-
The REST API for the inventory system uses the basic HTTP verbs to provide CRUD data access (minus the 'U' at this time.).
-
This demo app only supports routes for the Inventory system based on 'Label' parameter input at this time. This was done by modifying the default route template. For extensibility, this would need to be changed later so the default used 'id' as the parameter which is commonly used in REST apis.