Exercise - Run the app
In this unit, you'll use the HttpRepl tool to test the API. The API will use your code to interact with the database.
Run the app and connect
From the terminal, run the following command:
dotnet tool install -g Microsoft.dotnet-httpreplThis command installs the HttpRepl tool.
Run the app with the following command:
dotnet run --urls=https://localhost:5101This command launches the app and specifies the listening port to
5101.Inspect the output from running the app.
- EF Core echoes SQL commands as
infolog events as they execute. - If the database does not already exist, then the tables and indexes are defined with
CREATESQL commands. - If the database has not yet been seeded, then
INSERTcommands are executed to add the seed data. - For security, the parameter values are not echoed to the console. This can be changed using EnableSensitiveDataLogging
- EF Core echoes SQL commands as
Use SQLite Explorer to explore the seeded database. Each table has data.
Since the terminal is blocked by the running app, open another terminal (Ctrl+Shift+`) to test the app.
In the new terminal, run the following command:
httprepl https://localhost:5101HttpRepl connects to the running API and uses the OpenAPI specification to discover the available endpoints.
Test database operations
Now that you've connected with HttpRepl, let's try out our app. After each CRUD operation, inspect the database in SQLite Explorer to see the changes as they happen.
At the HttpRepl command prompt, run the following command to list the discovered endpoints.
lsSwitch to the
Pizzaendpoint.cd PizzaRun the following command to get the list of all pizzas.
getThe API returns the list of pizzas as JSON.
Note
Why are the
sauceandtoppingsproperties null? Remember in thePizzaService.GetAllmethod, you didn't use theIncludeextension method to specify that the navigation properties should be loaded.Run the following command to get a single pizza.
get 2The API returns the "Hawaiian" pizza. Notice that the
sauceandtoppingsproperties are populated because thePizzaService.GetByIdmethod uses theIncludeextension method.Run the following command to add a new pizza.
postVisual Studio Code opens a new tab with a temporary file. The file contains a template for posting a new pizza. Paste in the following JSON, save, and close the tab.
{ "name": "BBQ Beef", "sauce": { "name": "BBQ", "isVegan": false }, "toppings": [ { "name": "Smoked Beef Brisket", "calories": 250 } ] }Run the following command to add another topping to the new BBQ Beef pizza.
put 4/addtopping?toppingId=5 --no-bodyRun the following command to change the sauce on the BBQ Beef pizza.
put 4/updatesauce?sauceId=2 --no-bodyRun the following command to view the current BBQ Beef pizza.
get 4You've realized a smoked brisket pizza with Alfredo sauce and pineapple is a terrible idea. Delete it with the following command:
delete 4Enter
exitto leave HttpRepl.In the terminal with the running app, press Ctrl+C to stop the running app.
Tip
You may experiment with the app as you wish. Whenever you'd like to start with a fresh database, stop the app and delete the ContosoPizza.db, .db-shm, and .db-wal files, and then run the app again.
Great work! The app is working with your database as expected! In the next unit, you'll scaffold entity models from an existing database.
Need help? See our troubleshooting guide or provide specific feedback by reporting an issue.