Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rahulmule/contactsapp_dotnetrestapi
This repository contains a .NET Web API for managing contacts. The API allows you to perform CRUD operations (Create, Read, Update, Delete) on contacts stored in a SQL database.
https://github.com/rahulmule/contactsapp_dotnetrestapi
docker dot-net-core dotnet-6 dotnetwebapi entity-framework-core rest-api
Last synced: 3 days ago
JSON representation
This repository contains a .NET Web API for managing contacts. The API allows you to perform CRUD operations (Create, Read, Update, Delete) on contacts stored in a SQL database.
- Host: GitHub
- URL: https://github.com/rahulmule/contactsapp_dotnetrestapi
- Owner: RahulMule
- Created: 2024-01-05T12:53:11.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2024-03-02T19:52:07.000Z (9 months ago)
- Last Synced: 2024-03-03T18:45:04.372Z (9 months ago)
- Topics: docker, dot-net-core, dotnet-6, dotnetwebapi, entity-framework-core, rest-api
- Language: C#
- Homepage:
- Size: 29.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Contacts App Web API
This repository contains a .NET Web API for managing contacts. The API allows you to perform CRUD operations (Create, Read, Update, Delete) on contacts stored in a database.
## Project Structure
The project structure follows a typical ASP.NET Web API pattern, utilizing Entity Framework Core for database interaction.
- **Controllers:**
- `ContactsController`: Manages CRUD operations for contacts.- **Data:**
- `ContactsAppDbContext`: Entity Framework DbContext for handling contact data.- **Models:**
- `Contact`: Represents a contact entity.## API Endpoints
### 1. Get All Contacts
- **Endpoint:** `GET /api/Contacts`
- **Description:** Retrieve a list of all contacts.
- **Response:** Array of contacts.### 2. Get Contact by ID
- **Endpoint:** `GET /api/Contacts/{id}`
- **Description:** Retrieve a specific contact by ID.
- **Response:** Single contact or NotFound if not found.### 3. Update Contact
- **Endpoint:** `PUT /api/Contacts/{id}`
- **Description:** Update an existing contact.
- **Request Body:** JSON representing the updated contact.
- **Response:** NoContent on success, BadRequest if the ID in the route does not match the contact ID.### 4. Create Contact
- **Endpoint:** `POST /api/Contacts`
- **Description:** Create a new contact.
- **Request Body:** JSON representing the new contact.
- **Response:** CreatedAtAction with the new contact details.### 5. Delete Contact
- **Endpoint:** `DELETE /api/Contacts/{id}`
- **Description:** Delete a contact by ID.
- **Response:** NoContent on success, NotFound if the contact is not found.## How to Run
1. Clone this repository.
2. Set up a SQL Server or another compatible database and update the connection string in `appsettings.json`.
3. Run the application using Visual Studio or `dotnet run`.
4. Test the API using a tool like [Postman](https://www.postman.com/) or [Swagger](https://swagger.io/).## Docker Support
This project includes a Dockerfile to facilitate containerized deployment.
### Build Docker Image
To build the Docker image, run the following command in the project directory:
```bash
docker build -t contacts-app .
Once the Docker image is built, you can run a container using the following command:
docker run -p 8080:80 -d contacts-app## Dependencies
- ASP.NET Core
- Entity Framework Core
- Microsoft.Extensions.DependencyInjection
- Microsoft.EntityFrameworkCore.SqlServerFeel free to customize and extend this project based on your specific requirements. For any issues or improvements, please create an issue or submit a pull request.
Happy coding!