In this exercise we will build a HTTP API for keeping stock of our diamonds.
- In diamond.js, write code to create a sqlite database, with a single table that has the following fields (Explanations for all fields except id are available in the file prices-of-diamonds.html. id should be an auto-incrementing primary key.):
- id
- carat
- cut
- color
- clarity
- depth
- table
- price
- x
- y
- z
-
Write a function to load the contents of prices-of-diamonds into the database.
-
Add four methods to the express app in diamond.js to:
- GET a diamond by its id.
- POST a new diamond, which will respond with the new id of the diamond.
- PUT a new diamond at a given id.
- DELETE a diamond by its id.
- Test the use of the API using curl.
- Create a single HTML file to interact with the API using AJAX calls.
-
See the sqlite3 npm page here for an example of using a sqlite database in node.
-
See the node-sqlite3 GitHub page here for more information on using sqlite in node.
-
See the Express documentation here for example of using GET, POST, PUT and DELETE.
-
See this blog post for example of using Curl to test an API.