Address Book API is a backend project that allows users to manage their personal contacts efficiently. It is built using ASP.NET Core Web API, Entity Framework Core, and JWT Authentication with Role-Based Authorization.
This API supports CRUD (Create, Read, Update, Delete) operations for contacts, while JWT ensures authentication and roles (Admin/User) handle authorization.
- π JWT Authentication & Role-Based Authorization
- π§Ύ CRUD Operations on Contacts
- π§ Entity Framework Core for database management
- π Layered Architecture (Controller, Service, Model, Data)
- π§° Swagger Integration for API testing
- πΎ SQL Server Database Connection
| Category | Technology |
|---|---|
| Framework | ASP.NET Core Web API |
| Language | C# |
| Database | SQL Server |
| ORM | Entity Framework Core |
| Authentication | JWT (JSON Web Token) |
| Architecture | RESTful API |
| Testing Tool | Swagger UI |
| IDE | Visual Studio 2022 |
AddressBookApi/
β
βββ Controllers/
β βββ ContactsController.cs, AuthController.cs
β
βββ Data/
β βββ ApplicationDbContext.cs
β
βββ Models/
β βββ Contact.cs
β βββ User.cs,Role
β
βββ Services/
β βββ IContactService.cs
β βββ ContactService.cs, BetterContactServices.cs
β
βββ Helpers/
β βββ JwtHelper.cs
β
βββ Program.cs
βββ appsettings.json
git clone https://github.com/harshu10-coder/AddressBookApi.git
cd AddressBookApiappsettings.json Update your Connection String here:
"ConnectionStrings": { "DefaultConnection": "Server=YOUR_SERVER;Database=AddressBookDb;Trusted_Connection=True;TrustServerCertificate=True;" }
dotnet ef database update
dotnet run
Open Swagger UI:
π https://localhost:5001/swagger
- When a user logs in a JWT Token is generated.
- The token must be pasted into the Authorize button in Swagger.
- Only users with a valid token can access the protected endpoints.
Example Token Format:
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/Auth/register |
Register new user |
| POST | /api/Auth/login |
Login and get JWT token |
| Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /api/Contacts/allcontacts/all |
Get all contacts | Admin, User |
| GET | /api/Contacts/Contactedbyid/{id} |
Get contact by ID | Admin, User |
| POST | /api/Contacts/CreateContact/add |
Add a new contact | Admin |
| PUT | /api/Contacts/UpdateContact/{id} |
Update a contact | Admin |
| DELETE | /api/Contacts/deleteContact/{id} |
Delete a contact | Admin |
| Role | Permissions |
|---|---|
| Admin | Can Create, Update, Delete, and View all contacts |
| User | Can only View contacts |
- ASP.NET Core Web API development
- Using Entity Framework Core for database interaction
- Understanding JWT-based authentication
- Implementing role-based authorization
- Building RESTful API endpoints
- Testing API with Swagger
- .NET 8 SDK or higher
- SQL Server (local or remote)
- Visual Studio 2022 or VS Code
- Postman / Swagger for testing
Harsh Kumar
π BCA Student | π» Aspiring Full Stack Dot Net Developer
πΉ Skills: ASP.NET Core |Asp.NET WebApi| SQL Server | Oracle | HTML | CSS | Bootstrap | C# |
π GitHub: harshu10-coder
- β Add refresh token mechanism
- β Integrate frontend using ASP.NET MVC or React
- β Deploy API to Azure or Render
If you found this project useful, donβt forget to Star β it! It helps motivate me and encourages more new projects π
aspnet-core β’ webapi β’ restapi β’ jwt-authentication β’ entity-framework-core β’ sql-server β’ dotnet