MyStore API is an ASP.NET Core application that interacts with a SQL Server database. This project is designed to demonstrate how to set up a simple API with a database using Docker Compose.
Before you begin, ensure you have the following installed on your machine:
- Docker (including Docker Compose)
Follow these steps to run the application using Docker Compose.
-
Clone the Repository
git clone https://github.com/Zapwap123/MyStore.git cd MyStore -
Build and Run the Application
Use Docker Compose to build and run the services:
docker-compose up --build
This command will start the SQL Server database and the ASP.NET Core API. The application will be accessible at
http://localhost:5000. -
Access the API
You can test the API endpoints using a tool like Postman or by using
curlcommands. -
Stopping the Services
To stop the services, press
Ctrl + Cin the terminal where Docker Compose is running. You can also run:docker-compose down
This command will stop and remove the containers.
The connection to the SQL Server database is configured in the appsettings.json file, and the password for the sa user is defined in the docker-compose.yml file.
"ConnectionStrings": {
"DefaultConnection": "Server=db;Database=CustomerDB;User Id=sa;Password=YourPassword123;"
}You can test the CustomerController endpoints using the following paths:
-
Get All Customers (Paginated)
- Endpoint:
GET /api/customer - Query Parameters:
page(optional, default: 1): Page number for pagination.pageSize(optional, default: 10): Number of customers per page.
Example:
http://localhost:5000/api/customer?page=1&pageSize=10 - Endpoint:
-
Get Customer by Customer Number
- Endpoint:
GET /api/customer/{customerNumber} - Example:
http://localhost:5000/api/customer/12345
- Endpoint:
-
Create a New Customer
- Endpoint:
POST /api/customer - Body (JSON):
{ "customerNumber": "12345", "name": "John Doe", "email": "johndoe@example.com", "phone": "123-456-7890" } - Example:
http://localhost:5000/api/customer
- Endpoint:
-
Update Customer by Customer Number
- Endpoint:
PUT /api/customer/{customerNumber} - Body (JSON):
{ "customerNumber": "12345", "name": "Jane Doe", "email": "janedoe@example.com", "phone": "098-765-4321" } - Example:
http://localhost:5000/api/customer/12345
- Endpoint:
-
Delete Customer by Customer Number
- Endpoint:
DELETE /api/customer/{customerNumber} - Example:
http://localhost:5000/api/customer/12345
- Endpoint:
Use these paths to interact with the API in Postman. Make sure to set the Content-Type to application/json for POST and PUT requests.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a pull request or open an issue if you encounter any problems.
For any inquiries or feedback, feel free to reach out:
- Email: sethanmawen97@gmail.com
- LinkedIn: linkedin.com/in/seth-anmawen-30813721a