Skip to content

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.

Notifications You must be signed in to change notification settings

savaladaojr/CommanderAPI

Repository files navigation

Commander API

Commander API is a simple ASP.NET Core 3.1 MVC REST API that executes CRUD (Create, Retrieve, Update and Delete) commands 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 mvc - to create a new ASP.NET Core Web Application). It is a simple but useful tool when you need to find a specific command line to use it. So, you'll have it within your reach, quickly and without having to perform any search on Google ;).

Each command line will have the following attributes:

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

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

  • Platform
    Application or platform domain, e.g. .Net Core

Features

  • Retrieve all commands
  • Retrieve a spectic command
  • Create a new command
  • Update a command information
  • Delete an existent command

As the most REST APIs, the Commander API will follow the standard set of methods to Create, Retrieve, Update, and Delete records in the database. So, each functionality could be access as listed in the table below:
Verb URI Method Description
GET /api/commands Retrieve Retrieve all command line
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
DELETE /api/commands/{id} Delete Delete a single command line by Id

Installation

Pre-requisites

  1. .Net Core SDK installed;
  2. Visual Studio Code installed;
  3. Microsoft SQL Server Local DB installed;
  4. MS SQl Server - VSCode Extension - installed.

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 director that you clone the repository, by a command prompt, execute the command to open the Visual Sutdio 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";
    1.2. Create new user called "CommanderUser", set it password and set it as a CommanderDB owner;

  2. In the VSCode:
    2.1. Open the file "appsettings.json" and change the "ConnectionString" property to reflect your configuration;
    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 & Runnin 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 also use a Google Chrome plug-in. You also have another option which is Insomina. Both are gonna work 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.

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




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

No packages published

Languages