Butterfly critique is an API designed for butterfly enthusiasts. So far, it's an express
-based API that stores butterflies and users.
Data persistence is through a JSON-powered database called lowdb
.
Validation is built using an assertion library called @mapbox/fusspot
.
Butterfly critique is already a pretty great API, but we think it would be even better if it let users critique butterflies. Your task is to create new API endpoints that:
- Allow a user to rate butterflies on a scale of 0 through 5
- Allow retrieval of a list of a user's rated butterflies, sorted by rating
You should also provide a small write-up that explains the decisions (for instance, the HTTP verbs for new endpoints) and trade-offs you made. If you add any new dependencies, spend some time talking about why you chose them.
You are free to refactor or improve any code you think should be refactored, but please include a note about such changes in your write-up.
If you have any questions or concerns, please do not hesitate to contact us!
- Your code should be extensible and reusable
- Your code should be well tested
- Your code should be tidy and adhere to conventions
- Your write-up should be thoughtful and coherent
You will be scored on the following aspects of your work:
- Endpoint implementation
- Endpoint design
- Appropriate testing of new code
- Tidiness and adherence to conventions
- Appropriate refactoring
- Technical proficiency
- Communication in the write-up
0 = poor 1 = adequate 2 = exceptional
The maximum possible score is 14.
- Node v10.15.x
- npm v6
Install dependencies with:
npm install
If you need to recreate the butterflies database, you can run:
npm run init-db
To run the application locally:
npm start
You should see a message that the application has started:
Butterfly API started at http://localhost:8000
You can manually try out the application using curl
:
# GET a butterfly
curl http://localhost:8000/butterflies/xRKSdjkBt4
# POST a new butterfly
curl -X POST -d '{"commonName":"Brimstone", "species":"Gonepteryx rhamni", "article":"https://en.wikipedia.org/wiki/Gonepteryx_rhamni"}' -H 'content-type: application/json' http://localhost:8000/butterflies
# GET a user
curl http://localhost:8000/users/OOWzUaHLsK
For developing, you can run the application with auto-restarts on code changes using:
npm run watch
This project uses jest
as its testing framework.
If you are unfamiliar with jest
, check out its documentation.
This project has eslint
and a custom config @mapbox/eslint-config-mapbox
setup for code linting.
To run the linter and all tests:
npm test
For developing, you can run jest
with auto-restarts using:
npm run test-watch