Finished project β
-
.NET 6.0 or +
-
Connection string to SQLServer in BikeApi/appsettings.json named as Default
Create a database in SQLServer that contains the table created from the following script:
CREATE DATABASE BikeApiDapper
GO
Use BikeApiDapper
GO
CREATE TABLE Categories(
Id INT PRIMARY KEY IDENTITY(1, 1),
Name VARCHAR(80) NOT NULL
);
GO
CREATE TABLE Brands(
Id INT PRIMARY KEY IDENTITY(1, 1),
Name VARCHAR(80) NOT NULL
);
GO
CREATE TABLE Products(
Id INT PRIMARY KEY IDENTITY(1, 1),
Name VARCHAR(80) NOT NULL,
ModelYear SMALLINT NOT NULL,
Price DECIMAL(10, 2) NOT NULL,
BrandId INT NOT NULL,
CategoryId INT NOT NULL,
CONSTRAINT [FK_Products_Category] FOREIGN KEY (CategoryId)
REFERENCES Categories(Id),
CONSTRAINT [FK_Products_Brand]FOREIGN KEY (BrandId)
REFERENCES Brands(Id)
);
GO
+--------------+ +-------------+ +--------------+
| Categories | 1 * | Products | * 1 | Brands |
+--------------+ +-------------+ +--------------+
| Id |<-------| Id |------->| Id |
| Name | | Name | | Name |
| | | ModelYear | | |
| | | Price | | |
+--------------+ | BrandId | +--------------+
| CategoryId |
+-------------+
$ git clone https://github.com/lcsmota/BikeApi.git
$ cd BikeApi/
$ dotnet restore
$ dotnet run
Server listenning at https://localhost:7250/swagger or https://localhost:7250/api/v1/Products, https://localhost:7250/api/v1/Brands and https://localhost:7250/api/v1/Categories
GET https://localhost:7250/api/v1/Products
βοΈ Status Code:
(200) - OK
(404) - Not Found
GET https://localhost:7250/api/v1/Products/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to view |
βοΈ Status Code:
(200) - OK
(404) - Not Found
POST https://localhost:7250/api/v1/Products
π¨ body:
{
"name": "Trek 820",
"modelYear": 2016,
"price": 379.99,
"brandId": 9,
"categoryId": 6
}
π§Ύ response:
{
"modelYear": 2016,
"price": 379.99,
"brandId": 9,
"categoryId": 6,
"id": 12,
"name": "Trek 820"
}
βοΈ Status Code:
(201) - Created
PUT https://localhost:7250/api/v1/Products/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to update |
π¨ body:
{
"name": "Trek 820",
"price": 399.50
}
π§Ύ response:
βοΈ Status Code:
(204) - No Content
(404) - Not Found
DELETE https://localhost:7250/api/v1/Products/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to delete |
π¨ body:
π§Ύ response:
βοΈ Status Code:
(204) - No Content
(404) - Not Found
GET https://localhost:7250/api/v1/Categories
βοΈ Status Code:
(200) - OK
(404) - Not Found
GET https://localhost:7250/api/v1/Categories/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to view |
βοΈ Status Code:
(200) - OK
(404) - Not Found
GET https://localhost:7250/api/v1/Categories/${id}/multipleresults
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to view |
βοΈ Status Code:
(200) - OK
GET https://localhost:7250/api/v1/Categories/multiplemapping
βοΈ Status Code:
(200) - OK
POST https://localhost:7250/api/v1/Categories
π¨ body:
{
"name": "Children Bicycles"
}
π§Ύ response:
{
"products": [],
"id": 9,
"name": "Children Bicycles"
}
βοΈ Status Code:
(201) - Created
PUT https://localhost:7250/api/v1/Categories/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to update |
π¨ body:
{
"name": "Cyclocross Bicycles"
}
π§Ύ response:
βοΈ Status Code:
(204) - No Content
(404) - Not Found
DELETE https://localhost:7250/api/v1/Categories/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to delete |
π¨ body:
π§Ύ response:
βοΈ Status Code:
(204) - No Content
(404) - Not Found
GET https://localhost:7250/api/v1/Brands
βοΈ Status Code:
(200) - OK
(404) - Not Found
GET https://localhost:7250/api/v1/Brands/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to view |
βοΈ Status Code:
(200) - OK
(404) - Not Found
GET https://localhost:7250/api/v1/Brands/${id}/multipleresults
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to view |
βοΈ Status Code:
(200) - OK
GET https://localhost:7250/api/v1/Brands/multiplemapping
βοΈ Status Code:
(200) - OK
POST https://localhost:7250/api/v1/Brands
π¨ body:
{
"name": "Trek"
}
π§Ύ response:
{
"products": [],
"id": 11,
"name": "Trek"
}
βοΈ Status Code:
(201) - Created
PUT https://localhost:7250/api/v1/Brands/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to update |
π¨ body:
{
"name": "Sun Bicycles"
}
π§Ύ response:
βοΈ Status Code:
(204) - No Content
(404) - Not Found
DELETE https://localhost:7250/api/v1/Brands/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to delete |
π¨ body:
π§Ύ response:
βοΈ Status Code:
(204) - No Content
(404) - Not Found
- C# 10
- .NET CORE 6
- SQL SERVER
- Dapper
- Swagger
- DTOs
- Repository Pattern
- Dependency injection
- POO
Registration, Listing, Update and Removal