This repo establishes a relational data model, populates a SQLite database from a sample CSV file and fake data, and builds a REST API using Flask to communicate to the database.
git clone [email protected]:jessdaubner/sqlite-flask-api.git
Download and install Docker. Build the app locally docker build -t sqlite-flask-api .
.
Download and install Postman which will be used to send API requests to the service for testing.
Run the app, mapping your machine's port 5000 to the container's published port 80.
docker run -p 5000:80 sqlite-flask-api
It will take a few seconds for the database to populate and the API service to start. The app will run on http:https://localhost:5000
.
Method | Endpoint | Purpose |
---|---|---|
GET | /inventory/{inventory-id} |
Get ticket by inventoryId, for testing |
GET | /inventory/event/{event-id} |
Get available tickets for an event |
GET | /inventory/best-ticket/{event-id} |
Get "best"/cheapest tickt for an event |
POST | /inventory |
Add ticket to inventory |
PUT | /inventory/sold/{inventory-id} |
Update a ticket to sold |
The files in postman/
contain sample requests to test the API calls that update or add records to the database. Note that only 164, 107, and 162 are valid values for event-id
while inventory-id
created from the imported sample data will range from 1 to 1533.
With the method set to GET (the default option), enter the request URL of the route you'd like to test, hit "Send" and view the response. For example, request URLs include http:https://localhost:5000/inventory/event/164
, http:https://localhost:5000/inventory/best-ticket/107
, and http:https://localhost:5000/inventory/12
.
- In the "Headers" tab add a new key-value pair of
Content-Type
andapplication/json
in order to set the content-type header to JSON. - In the "Body" tab, select the "raw" radio button and copy-and-paste an entry from
/postman/put_test.json
or create your own (inventoryId
must be unique). - Change the method to POST in the drop-down menu, fill-in the request URL (e.g,
http:https://localhost:5000/inventory
) and hit "Send".
- In the "Headers" tab, add a new key-value pair of
Content-Type
andapplication/json
in order to set the content-type header to JSON. - In the "Body" tab, select the "raw" radio button and add an entry in the format of
{"inventoryId": 56}
. - Change the method to PUT in the drop-down menu and enter a valid request URL (e.g,
http:https://localhost:5000/inventory/sold/56
) corresponding to theinventoryId
value in the request body. - Hit "Send" and view the 204 response. You can also send a GET request before and after the PUT request for the same
inventoryId
to see the status change from "AVAILABLE" to "SOLD".