Ultimate .NET Web API is a robust backend solution designed to handle various complex operations efficiently. This API provides a comprehensive set of features that are essential for modern web applications.
- Key Features
- CORS (Cross-Origin Resource Sharing)
- Logging Service
- Repository Pattern
- DTO (Data Transfer Object) Classes
- Global Error Handling
- Model Validation
- Asynchronous Code
- Modular Design
- Advanced Querying Capabilities
- Paging
- Filtering
- Searching
- Sorting
- Data Shaping
- Rate Limiting
- JWT and Identity for Authentication and Authorization
- API Documentation with Swagger
- API Routes
- Getting Started
- Contributing
- Conclusion
- Acknowledgements
- License
- Configured CORS to allow cross-origin requests from any origin, method, and header.
- Exposed pagination metadata in the headers.
- Implemented a centralized logging service to capture and manage logs, aiding in monitoring and debugging.
- Employed the repository pattern to abstract data access logic, making the code more modular and maintainable.
- Used DTOs to ensure a clear separation between the data models and API responses, improving data integrity and security.
- Integrated global error handling to manage exceptions consistently across the entire application.
- Implemented model validation to ensure data integrity before processing requests.
- Utilized asynchronous programming to improve performance and scalability.
- Structured the codebase into different classes and layers to promote modularity and reusability.
- Paging: Implemented pagination to handle large datasets efficiently.
- Filtering: Added filtering capabilities to retrieve data based on specific criteria.
- Searching: Integrated search functionality to allow quick data retrieval.
- Sorting: Enabled sorting to organize data based on user-defined parameters.
- Data Shaping: Provided data shaping options to return only the requested fields in the response.
- Implemented rate limiting to control the number of requests a client can make to the API, ensuring fair use and preventing abuse.
- Utilized JWT and ASP.NET Core Identity for secure authentication and role-based authorization.
- Implemented refresh tokens for maintaining session security.
- Documented the API endpoints and models using Swagger for easy exploration and testing.
- .NET 8 SDK
- SQL Server (or any other compatible database)
-
Clone the repository:
https://github.com/YeabTesfaye/Ultimate.ASP.NET.Core.Web.API cd Ultimate-Dotnet-Web-API
-
Set up the database:
-
Update the connection string in
appsettings.json
. -
Apply migrations:
dotnet ef database update
-
-
Build the project:
dotnet build
-
Run the project:
dotnet run
- Access the Swagger documentation at
http://localhost:3000/swagger
to explore and test the API endpoints.
I Register a new user
-
POST
http://localhost:3000/api/authentication
-
Body:
{ "firstName": "string", "lastName": "string", "userName": "string", "password": "string", "email": "string", "phoneNumber": "string", "roles": ["string"] }
I Login a user
-
POST
http://localhost:3000/api/authentication/login
-
Body:
{
"username": "string",
"password": "string"
}
I Retrieve the list of all companies
- GET
http://localhost:3000/api/companies
II Create a new company
- POST
http://localhost:3000/api/companies
- Body
{
"name": "string",
"address": "string",
"country": "string",
"employees": [
{
"name": "string",
"age": "integer",
"position": "string"
}
]
}
III Retrieve a company by its unique id
- GET
http://localhost:3000/api/companies/{id}
IV Delete a company by its unique id
- DELETE
http://localhost:3000/api/companies/{id}
V Update a company by its unique id
- PUT
http://localhost:3000/api/companies/{id}
VI Retrieve companies by their ids
- GET
http://localhost:3000/api/companies/{ids}
VII Create a collection of new companies
- POST
http://localhost:3000/api/companies/{ids}
I Retrieve a list of employees for a specific company
- GET
http://localhost:3000/api/{companyId}/employees
II Create a new employee for a specific company
-
GET
http://localhost:3000/api/{companyId}/employees
-
Body
{ "name": "string", "age": "integer", "position": "string" }
III Retrieve an employee by their id
- GET
http://localhost:3000/api/{companyId}/employees/{id}
IV Delete an employee from a specific company
- DELETE
http://localhost:3000/api/{companyId}/employees/{id}
V Update an existing employee in a specific company
- PUT
http://localhost:3000/api/{companyId}/employees/{id}
VI Partially update an existing employee in a specific company
- PATCH
http://localhost:3000/api/{companyId}/employees/{id}
I Retrieve a refersh token
- POST
http://localhost:3000/api/token/refresh
-body
{
"token": "string",
"refreshToken": "string"
}
Contributions are welcome! Please fork the repository and create a pull request.
Ultimate .NET Web API is a comprehensive backend solution that integrates a wide range of essential features for modern web applications. From robust security measures to advanced querying capabilities, this API is designed to be scalable, maintainable, and easy to use. Whether you're building a small project or a large-scale enterprise application, Ultimate .NET Web API offers the tools and structure you need to succeed. Your contributions and feedback are highly appreciated as we continue to improve and expand the functionality of this API.
A special thanks to Code Maze for their insightful book "Ultimate ASP.NET Core Web API," which served as a valuable resource in the development of this project.