The Medusa.NET API is a sample source code that demonstrates a comprehensive API service, featuring a range of endpoints including Employees, Departments, Salaries, and Payment Methods. Each endpoint is equipped with full CRUD (Create, Read, Update, Delete) functionality, leveraging a database built on SQL Server.
To get started, download the project and follow these steps to build and run the application:
1.- Open a terminal or command prompt in the project directory. 2.- Run the command:
dotnet buildTo build the application.
Alternatively, you can open the project in Visual Studio and press F5 or click the "Run" button to build and run the application in debug mode.
With the application built, you can now start it by running the following command:
dotnet runThis will launch the application and make it available for use. You can then access the API endpoints using a tool like Postman or cURL.
The following API endpoints are available for use:
GET /api/Employee
Retrieves a list of all employees.
curl -X GET \
http://localhost:5133/api/Employee \
-H 'Content-Type: application/json'[
{
"employee_id": 1,
"first_Name": "John",
"last_Name": "Doe",
"start_Date": "2024-05-05T00:00:00",
"birthday": "1990-02-12T00:00:00",
"department_id": 1
},
{
"employee_id": 2,
"first_Name": "Jane",
"last_Name": "Smith",
"start_Date": "2019-06-01T00:00:00",
"birthday": "1992-08-25T00:00:00",
"department_id": 2
}
]GET /api/Employee/{id}
Retrieve the information of a specific Employee.
curl -X GET \
http://localhost:5133/api/Employee/11 \
-H 'Content-Type: application/json'{
"employee_id": 1,
"first_Name": "John",
"last_Name": "Doe",
"start_Date": "2024-05-05T00:00:00",
"birthday": "1990-02-12T00:00:00",
"department_id": 1
}POST /api/Employee
Create a new employee.
curl -X POST \
http://localhost:5133/api/Employee/ \
-H 'Content-Type: application/json' \
-d '{"first_Name": "Juan", "last_Name": "Escutia", "start_Date": "2022-01-01T00:00:00", "birthday": "1990-01-01T00:00:00", "department_id": 6}'{
"employee_id": 14,
"first_Name": "Juan",
"last_Name": "Escutia",
"start_Date": "2022-01-01T00:00:00",
"birthday": "1990-01-01T00:00:00",
"department_id": 6
}PUT /api/Employee/{id}
Update an actual employee.
curl -X PUT \
http://localhost:5133/api/Employee/12 \
-H 'Content-Type: application/json' \
-d '{"first_Name": "Juanito", "last_Name": "Escutia", "start_Date": "2022-01-01T00:00:00", "birthday": "1990-01-01T00:00:00", "department_id": 3}'We are going to receive a Status 204 with No Content.DELETE /api/Employee/{id}
Delete an actual employee.
curl -X DELETE \
http://localhost:5133/api/Employee/11We are going to receive a Status 204 withDepartment: /api/Department
Salary: /api/Salary
Payment Methods: /api/PaymentMethod
We have similar endpoints for the Department, Salary, and Payment Method modules, which mirror the Employees endpoints. The main difference lies in the endpoint name and the structure of the data being sent or received.
Department:
{
"department_description": "Example"
}
Salary:
{
"employee_id": 18,
"monthly_salary": 9550.56,
"payment_method_id": 2
}
PaymentMethod:
{
"payment_method_name": "Cash"
}
The following SQL queries are designed to create the necessary tables for our project, providing the foundation for our database structure.
CREATE TABLE employees (
employee_id INT IDENTITY(1,1) PRIMARY KEY,
first_Name NVARCHAR(50) NOT NULL,
last_Name NVARCHAR(50) NOT NULL,
start_Date DATE NOT NULL,
birthday DATE NOT NULL,
department_id INT
);CREATE TABLE payment_methods (
payment_method_id INT IDENTITY(1,1) PRIMARY KEY,
payment_method_name NVARCHAR(50) NOT NULL
);CREATE TABLE salaries (
salary_id INT IDENTITY(1,1) PRIMARY KEY,
employee_id INT NOT NULL,
monthly_salary DECIMAL(10, 2) NOT NULL,
payment_method_id INT NOT NULL,
FOREIGN KEY (employee_id) REFERENCES employee(employee_id),
FOREIGN KEY (payment_method_id) REFERENCES payment_methods(payment_method_id)
);CREATE TABLE [dbo].[departments] (
department_id INT IDENTITY(1,1) PRIMARY KEY,
department_description NVARCHAR(100) NOT NULL
);This repository is provided "as is" and without warranty of any kind. Use at your own risk. While we hope this repository helps you get started with.NET APIs, you are responsible for modifying and adapting the code to suit your specific needs. You may improve or change the endpoints as necessary, but please be aware that we do not guarantee the accuracy, completeness, or reliability of the code.
Medusa .NET API - Gabriel A.R.