Skip to content

savaladaojr/CommanderAPI

Repository files navigation

Commander API

Commander API is a simple ASP.NET Core/.NET 10 LTS REST API that executes CRUD (Create, Retrieve, Update and Delete) operations on an MS SQL Server database using Entity Framework Core.

GitHub language count GitHub top language .NET Core GitHub issues GitHub issues


Description

The Commander API stores command line snippets (e.g. dotnet new webapi to create a new ASP.NET Core Web API). It is a simple but useful tool when you need to find a specific command line quickly.

Each command line will have the following attributes:

  • How to
    Description of what the command will do, e.g. Build a .NET project

  • Command line
    The actual command line snippet, e.g. dotnet build

  • Platform
    Application or platform domain, e.g. .NET

The API is currently built with:

  • .NET 10 LTS
  • ASP.NET Core MVC Controllers
  • Entity Framework Core 10
  • SQL Server / LocalDB
  • AutoMapper
  • Newtonsoft.Json and JSON Patch support

Features

  • Retrieve all commands
  • Retrieve a specific command
  • Create a new command
  • Update command information
  • Partially update command information
  • Delete an existing command

As with most REST APIs, Commander API follows the standard set of methods to create, retrieve, update, and delete records in the database. Each functionality can be accessed as listed in the table below:
Verb URI Method Description
GET /api/commands Retrieve Retrieve all command lines
GET /api/commands/{id} Retrieve Retrieve a single resource, (by Id)
POST /api/commands Create Create a new command line
PUT /api/commands/{id} Update Update a single command line by Id
PATCH /api/commands/{id} Partial update Partially update a single command line by Id using JSON Patch
DELETE /api/commands/{id} Delete Delete a single command line by Id

Installation

Pre-requisites

  1. .NET 10 SDK installed;
  2. Visual Studio Code installed;
  3. Microsoft SQL Server Local DB installed;
  4. MS SQL Server - VSCode Extension - installed;
  5. Entity Framework Core CLI tool installed or available through your .NET tooling.

Cloning the Repository

  1. Create a project's directory on your computer;
  2. Clone the repository.
git clone https://github.com/savaladaojr/CommanderAPI

Running the API

Opening the project

  1. On the directory where you cloned the repository, open a command prompt and execute the command to open Visual Studio Code and load the project folder. You should see something like the screenshot below.
code .

Visual Studio Code - Project's structure

Restoring project's dependencies

  1. In the Visual Studio Code, open a Terminal and run the command to restore all packages used by the API;
dotnet restore

Updating the Database

  1. Connect on the SQL Server Local DB:
    1.1. Create a new database "CommanderDB" or let Entity Framework create it from the migrations;
    1.2. Make sure your Windows user has permission to access the database when using the default trusted connection;

  2. In the VSCode:
    2.1. Open the file "appsettings.json" and change the "CommanderConnection" connection string to reflect your environment, if needed;
    2.2. Open a new Terminal and run the command to update the database with the project's database migrations.

dotnet ef database update

Building & Running the API

  1. Then rebuild the application;
dotnet build

Visual Studio Code - Project's structure

  1. Run the API.
dotnet run

Visual Studio Code - Project's structure

Consuming the API.

To run some tests on the API, I recommend that you download Postman or use a Google Chrome plug-in. You also have another option, Insomnia. Both work well and have a free version.

I'm using Postman! So I have already prepared a file with all requests for the API. You can find this file (Commands API.postman_collection.json) in the repository.

Example of a request to the API: Visual Studio Code - Project's structure

Example payload

{
  "howTo": "Build the project",
  "line": "dotnet build",
  "platform": ".NET"
}

Current response contract

Read operations return the following fields:

  • id
  • howTo
  • line
  • platform

Migration notes

This project was migrated from ASP.NET Core 3.1 to .NET 10 LTS. The application now uses the modern hosting model in Program.cs; the old Startup.cs file was removed. The default local connection string no longer stores a username or password in the repository.

Additional architecture and requirements details are documented in docs/REQUISITOS_APLICACAO.md.




Contributing

  1. Fork it (https://github.com/savaladaojr/CommanderAPI/fork);
  2. Create your feature branch (e.g. git checkout -b feature/fooBar);
  3. Commit your changes (e.g. git commit -am 'Add some fooBar');
  4. Push to the branch (e.g. git push origin feature/fooBar);
  5. Create a new Pull Request.






This API was built for learning purposes. I did follow the instructions from the Dotnetplaybook website.

About

It is a simple ASP.NET Core 3.1 MVC REST API that executes CRUD commands through the entity framework core. It also includes how to work with the Repository Pattern, Unit of Work, and SOLID principles.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages