Skip to content
Mohammed Abbod edited this page Nov 26, 2022 · 2 revisions

Create "ASP.NET Core Web API" project

!

Set the name of the project, and Location:

!

Then uncheck the "Use Controller" checkbox to switch for Minimal API and OpenAPI:

!

Then build the EntityFramework (next page)

So when you created the EntityFramework DBContet and connected to the Database, now it’s the time to create the Minimal API functions:

Open the Program.cs

And add the DbUsersContext to the Services collection of DependencyInjection

!

And before app.run() method, add the functions of the API

!

Add the Minimal API Method:

!

Or the best option is adding the async/await style to this function:

!

One more function and the testing will be easy and clear, by creating the Add function: So after the GetUsers, Add the AddUser

!

Now its time to test, just run the app:

!

And let's add a user:

Click on "Post" to add the user:

!

And then on the try:

!

There is a structure of the class that created earlier in the EntityFramework section needs to fill and post:

!

And hit "Execute"

!

The result will be in the response, shows a successful submit (Post)

!

Then we can test the first method "GetUsers" after we have a new record in the database

Click on the GET

!

And you'll see the result:

!

This is in details how to interact with EntityFramework and Minimal API in .NET 7

The next step is how to add a method in Minimal API that will create a token for user and return it simply through a POST call.