- The SQLite database is created and populated as directed.
- Configuration and context registration use the SQLite provider and correct database path.
- Existing GET and POST operations still reach the intended data.
12.4 Lab - Deploying API Web Service
In this lab, we will be using our Netflix Titles web service application, created in 12.3 Lab and get it ready for deployment, then we will deploy the readied service using FTP and Microsoft Azure.
Work through the stories in order. Use the acceptance criteria to check each feature, and complete the nested tasks using the specified names, values, and scenarios.
| Operation | Checkpoint response |
|---|---|
| GET | 200 OK with the requested data. |
| POST | 200 OK with the created result, as required here. |
| PUT (12.4 onward) | 200 OK after the update. |
| DELETE (12.5) | 204 No Content after deletion. |
NetflixTitles.db
NetflixTitles.db"ConnectionStrings": { "DefaultConnection": "Data Source=./NetflixTitles.db" }
_ = services.AddDbContext<DataContext>
(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));dotnet tool install --global dotnet-ef --version 5.0.0install --global dotnet-ef --version 5.0.0You may need to update your framework and packaged to the 5.0.0 versions.
dotnet ef migrations add InitialCreatemigrations add InitialCreatedotnet ef database updatedatabase updateCall the _dataContext's field Update method, passing in the title parameter.
Call the _dataContext's field SaveChanges method.
Create a method named UpdateTitle that returns an IActionResult and accepts a parameter of type TitleDTO named titleDTO. Add the [FromBody] attribute to the parameter.
Add an HttpPut attribute to the method with a route of update/title.
Call the _dataService field's GetTitles method and set the result to a new list of Title named title.
Find the title with the same Id as the titleDTO Id in the titles list.
Title title = titles.Find(x => x.Id == titleDTO.Id);Set all the titleDTO properties to the corresponding title properites
You do not need to set the title's TitleCategory property.
Call the _dataService's UpdateTitle method passing in the title variable.
{{domain}}/api/update/titleIn the body tab of the request, select the raw radio button and JSON from the dropdown menu. Paste in the below JSON object, that updates the dateAdded property of the existing title, Norm of the North: King Sized Adventure.
{
"id": 1,
"categories": [
{
"id": 1,
"category": "Children & Family Movies"
},
{
"id": 2,
"category": "Comedies"
}
],
"dateAdded": "12/9/2019",
"description": "Before planning an awesome wedding for his grandfather, a polar bear king must take back a stolen artifact from an evil archaeologist first.",
"duration": "90 min",
"title": "Norm of the North: King Sized Adventure",
"rating": "TV-PG",
"releaseYear": 2019,
"showId": 81145628,
"type": {
"id": 1,
"type": "Movie"
}
}
<ItemGroup> <Content Remove="dist\**"/> </ItemGroup>
If you do not already have it installed, download and install the LTS (Long-Term Support) version of Node.js. If you are on Windows, you'll want the Windows Installer (.msi) 64-bit. If you are on a different platform, select the appropriate alternative.
Node.js Downloads
Node.js DownloadsCreate a new text file named package.json in your NetflixTitles project folder, parallel to your NetflixTitles.csproj. Copy the provided JSON below into the package.json file and save it.
{
"scripts": {}
}
Click on this link if you would like more information about the npx package
Click on this link if you would like more information about the npx packageRun the following command to install the npx package.
npm install npx
Check your work: Open the package.json file in your project folder and confirm that there is an entry under dependencies for the package you just installed.
Script out the tasks that should be performed when the script is ran. The scripts will prepare our application for deployment by building and publishing it to a dist folder.
dist is short for distribution, and is a common practice name to use for the folder that will get distributed to the users.
"publish-to-folder": : "dotnet publish --configuration Release --output ./dist"Check your work: In the terminal, run the following command to run the script you just added. If it is successful, you should have a folder named dist with the compiled application files in it.
npm run publish-to-folderpublish-to-folderAdd a script to the package.json file under the scripts area that can be used to bundle any scripts that you may want to add in the future, so that you would not need to run each of them individually every time you wanted to run the build.
"build": "npm run publish-to-folder"
Use a comma (,) to separate the scripts.
Check your work: Delete the dist folder created by running the previous script. In the terminal, run the following command to run the script that contains the other script. If it is successful, you should see the dist was re-created.
npm run buildbuildMicrosoft Azure Portal
Microsoft Azure PortalEach App Service would act as its own web host.
A resource group is a collection of resources. It is used to help organize your Apps and its resources (Database servers, VMS, etc.) You can use the same group for all App Services.
Choose a unique name for your App Service. The name will become part of the URL for your website e.g. https://YourName.azurewebsites.net/

Depending on server load, it may take a few minutes to create the App Service.

Until you deploy your application, you will see a placeholder page.



Create a new environment
Click on the Manage Environments button in the right hand corner, next to the button with the eye.
In the Manage Environments screen, click the Add button.
Name the environment Production
In the Variable section add a new variable named Domain and set the initial value to your websites name/api, similar to what is shown below.
https://knt.azurewebsites.net/apiClick Add.
Test each of the calls in Postman and ensure that they work correctly.
Make a copy of your project folder, in the copy of your project, delete the node_modules folder located in the same directory as your .csproj file location.
The node_modules folder enables you to run your build script for your application, however the file names are too long to allow windows to zip the containing folder. This is why you will be submitting a copy of your application with the node_modules folder removed.
Make a copy of your project folder, in the copy of your project, delete the node_modules folder located in the same directory as your .csproj file location.
Return to each story and verify its acceptance criteria. Preserve the submission format and destination stated in the activity; a reading, setup guide, lab, video demonstration, and oral final may require different evidence.
Use SQLite for the deployed service Update a title Publish and deploy the Netflix Titles API