Telechargé par Nor Nor

API REST

publicité
API-REST
Step 1: Set up a new Database Context
1. Create a new Database Context class, named DB_Demo_APIContext.cs
2. Add the new Connection in the appsettings.json file
3. Register the database connection context into Class starup.cs inside
ConfigureServices
Step 2: Work with a database using Entity Framework code first appoach
Step 3: Scaffold API Controller with Action using Entity Framework
•Right-click the Controllers folder.
•Select Add > New Scaffolded Item.
•Select API Controller with actions, using Entity Framework, and then select Add.
Step 4: Add Swagger client for Web API
1. Install Swagger Client
Add the Swagger generator to the services collection in the Startup.ConfigureServices method
2. Register Swagger Client in startup.json file
Add the Swagger generator to the services collection in the Startup.ConfigureServices
method
Enable the middleware for serving the generated JSON document and the Swagger
UI, in the Startup.Configure method
Step 5: Run and Test the app
Before we run the app, modify the header of the file: Views/Shared/_layout.cshtml
Views again, shown below
Now, we run the app
Click Web API, we got the Swagger Client screen
TESTER AVEC ARC
Téléchargement