Similar presentations:
TW_Prezentare_v2
1. TEHNOLOGII WEB
antohi.ionel@gmail.com2. GETTING STARTED
IntroductionHow Did We Do?
GETTING
STARTED
Project Organization
Top Issues Facing In Visual Studio 2015-2017
Project References (NuGet Packages)
Project Configuration
First Run
3. Introduction
In this course we'll provide an introduction to ASP.NET Core Web API by building aRESTful service that uses Entity Framework Core and EF migrations to interact
with SQL Server. We'll explore the modern .NET 8/9 hosting model, dependency
injection, and the middleware pipeline. The course covers both minimal APIs and
controller-based approaches, async programming with the Task-based model,
and best practices for building scalable backend services. We'll also look at
configuration management with appsettings.json, API documentation with
OpenAPI/Swagger, and common patterns for authentication and error handling in
production APIs.
4. SOLUTION SETUP
1. File > New > Project…2. Search for Blank Solution
3. Next
5. SOLUTION SETUP
1. Set a Solution Name2. Set a Location for your
solution
3. Create
6. ADD PROJECT TO SOLUTION
R-Clickon
Solution Name
From menu select : Add
Click : New Project
7. WEB PROJECT
1.Select Language C#2.Search for .net core
3. Select
ASP.NET Core Empty
4. Next
Note
Save Solution name as
main namespaces ex:
eUseControl.[project
name]
8. Set Name of the Solution to match the Initial Namespace
9. PROJECT TEMPLATES
10. PROJECT View
At this stage, you have a cleansolution that is not yet configured.
Your next step is to make the key
decisions about how to set it up and
how you want it to work.
This is an important moment in the
project because you have full
freedom to build a strong foundation
from the start. You can:
• - add the necessary configuration
early (environment settings,
dependencies, project structure);
• - design and implement the core
logic in a clear and maintainable
way;
• - define rules and structure that will
keep the project consistent as it
grows.
In other words, you are building the
project from scratch, with the
architecture and workflow under
your control—an excellent
opportunity to learn how to design
and organize a real solution the right
way.
11. Enable Swagger for Your .NET Core Web API
Before creating your first controller, the project should be prepared for API testingand documentation. For this, the application will use Swagger.
Enable
Swagger
for Your
.NET Core
Web API
What is Swagger?
Swagger (OpenAPI) is a standard way to describe REST APIs. In .NET, it is
commonly used to:
automatically generate interactive API documentation
provide a built-in web page (Swagger UI) where you can test endpoints (GET/POST/etc.)
make it easy to understand what endpoints exist, what parameters they accept, and what responses they return
support collaboration between developers and testers, because the API contract becomes visible and clear
Why do we add it at the beginning?
Adding Swagger early is useful because every time you create a new controller or
endpoint, it will appear automatically in Swagger UI. This makes development and
verification much faster.
12. Add Swagger To Project Step 1
13. Install Swagger Package
14.
15. Configure Swagger in Program.cs
16. Controller
In an ASP.NET Core Web API project, a controller is a C# class that defines the APIendpoints your application exposes to the outside world.
A controller is responsible for:
• receiving HTTP requests (GET, POST, PUT, DELETE)
Controller
• reading input (route parameters, query strings, request body)
• calling the application logic (services / business logic)
• returning a response (usually JSON + HTTP status code)
Lets Create our First Controller
17. 1. Add a new folder Controller inside solution. 2. In the Controller folder add first Controller Class.
18.
19.
20.
21. First API Endpoint
22.
23. Domain Entities & CRUD Operations
Domain Entities &CRUD Operations
24. Objectives
By the end of this lesson, you will be able to:Understand what a Domain entity represents
Create Domain entity classes
Objectives
Implement all CRUD operations (Create, Read,
Update, Delete)
Use appropriate HTTP methods and status codes
Test a complete API workflow in Swagger
25. What is a Domain Entity?
A Domain entity represents a real-world object or concept thatyour application works with.
What is a
Domain
Entity?
Think of it as the "things" your system manages:
- A User in a user management system
- A Product in an e-commerce application
- An Order in an ordering system
- A Student in a university system
26. Why "Domain"?
The term "Domain" comes from Domain-Driven Design (DDD) - a softwaredesign approach that focuses on the core business logic.
In our project structure:
Why
"Domain"?
- We use a `Domain` folder to store our entities
- This prepares us for future architecture where Domain becomes its own
project layer
Domain Entity - Represents core business objects (User, Product, Order)
Model - Can mean different things: UIModel, DTO, Request/Response
objects
27. Creating Your First Domain Entity
Why `= string.Empty`?In .NET 8 with nullable enabled, we
initialize strings to prevent null
reference warnings.
This ensures our properties always have a
value.
28. HTTP Methods & Status Codes
HTTPMethods
& Status
Codes
29. Common HTTP Status Codes (Web API)
Success (2xx)Common
HTTP
Status
Codes
(Web API)
• 200 OK — request succeeded (GET / PUT)
• 201 Created — resource created (POST)
• 204 No Content — deleted successfully (DELETE, no body)
Client Errors (4xx)
• 400 Bad Request — invalid input / validation failed
• 404 Not Found — resource doesn’t exist (wrong id)
30. Quick examples Request → Response
- GET /api/users → 200 OK + list- GET /api/users/1 → 200 OK + user
Quick
examples
Request
→
Response
- GET /api/users/999 → 404 Not Found
- POST /api/users → 201 Created + created user
- POST /api/users (invalid) → 400 Bad Request
- PUT /api/users/1 → 200 OK + updated user
- PUT /api/users/999 → 404 Not Found
- DELETE /api/users/1 → 204 No Content
- DELETE /api/users/999 → 404 Not Found
31. Building UserController with CRUD
32.
33.
34.
35.
36.
37.
38.
39. What We Learned?
Domain Entity - A class representing real-world business objectsCRUD - Create, Read, Update, Delete operations
HTTP Methods - GET, POST, PUT, DELETE for different operations
Status Codes -200, 201, 204, 404 for different responses
What We
Learned?
Important Note
The current implementation uses in-memory storage
(static List).
This means:
- Data is lost when the application restarts
- Data is not shared between multiple instances
40. Home Work
Exercise 1: Add a New PropertyAdd a `IsActive` property (bool) to the User entity.
Update the controller to handle this new property.
Exercise 2: Create Another Entity
Home
Work
Create a `Product` entity with properties: Id, Name,
Price, Description. Create a `ProductController` with
full CRUD operations.
Exercise 3: Add Validation
Modify the POST method to return 400 Bad Request if the
Username is empty.