A set of endpoints to demonstrate 4 use-cases.
Node.js was selected for this project because of its great performance, intuitive environment and as a personal preference for developing projects in the past 3 years.
MongoDB was selected for its simplicity to quickly prototype a small project.
Express.js was chosen as a tool to build the exercise-api for its well structured layout.
Other packages that are used in the app:
mongoose - a schema based solution to model app objects
Faker - to make fake data less boring
mocha - a Javascript test framework, a well featured tool for testing
should - an assertion library for tests
sinon - an excellent framework to create stubs, mocks, and spies for tests
istanbul - a test coverage tool to generate a test coverate report
1. Installed node
2. Installed npm
3. Installed and running mongodb
-
Clone the app
$ git clone https://github.com/MaxKramnik/exercise-api.git
-
Install packages
$ npm install
- Insert test data (again, assuming mongodb is running as localhost, if not, make an appropriate config change in /config/config.js ). You need to run this only once, but if you run it multiple times, it will simply regenerate 100 new user documents in db
```bash
$ make data
```
- Start the app:
```
$ node app
# or
$ npm start
# or
$ make server
```
Assuming the app is running, the app can be tested by simply copy/pasted the links bellow in the browser window:
- An account with the credentials admin for username and admin for password is the user account that would allow to authenticate, it should return a user object:
http://localhost:3000/v1/auth?username=admin&password=admin
- This should return status code 403, permission denied:
http://localhost:3000/v1/auth?username=test1&password=test2
- A list of users:
- A list of users, page 4:
http://localhost:3000/v1/list/4
- A list of female users:
http://localhost:3000/v1/list?gender=female
- A list of users sorted by country:
http://localhost:3000/v1/list/2?gender=male&groupby=country
- The system health state:
http://localhost:3000/v1/health
- Traverse an existing directory:
http://localhost:3000/v1/traverse?directory=/usr/bin
- Try to traverse a non existing directory:
http://localhost:3000/v1/traverse?directory=/something
Or use cUrl with any of those links in the terminal, like an example below:
$ curl -i -X GET http://localhost:3000/v1/list?gender=female
All endpoints start with /v1, in order to provide a flexible way to change the endpoints without breaking the current application that may still consume the older version. To create a new version of the endpoint, the developer will add /v2 (and so on) for a new version of the code to the endpoint.
$ make test
- A couple of methods are skipped for unit test, because they were not used directly by the endpoints, only to populate records
$ make test-cov