Skip to content

Repository files navigation

Contributors Forks Stargazers Issues project_license LinkedIn


Logo

Pilot API

A proof of concept API to explore best-practices and new ideas
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. Copilot Customization
  7. License
  8. Contact
  9. Acknowledgments

About The Project

A proof of concept API to explore best-practices and new ideas

(back to top)

Built With

  • Bruno
  • C#
  • GitHub Copilot
  • Microsoft SQL Server
  • OpenAPI
  • Postgres
  • Swagger
  • Visual Studio

(back to top)

Getting Started

This application depends on Docker for databases and an API deployment location.

Docker install and setup details can be found here: Local Docker

The design of this application was based upon the OpenAPI specification, found in the shared\PilotSharedSource directory (which is a submodule of PilotSharedSource).

Prerequisites

Installation

  1. Clone the repo (including submodules)

     git clone --recurse-submodules https://github.com/MikeLooper/PilotApiDotNet.git
    
  2. If the repository was cloned without submodules, initialize them:

    git submodule update --init --recursive
    
  3. Open the .sln file in Visual Studio.

  4. Press F5 to build and run the application.

Submodule Management

This repository includes PilotSharedSource as a Git submodule at shared/PilotSharedSource/.

To pull the latest submodule changes from its tracked branch:

git submodule update --remote --recursive shared/PilotSharedSource

After updating, commit the changed submodule pointer in this repository:

git add shared/PilotSharedSource .gitmodules
git commit -m "Update PilotSharedSource submodule"

(back to top)

Local Development

When Executing locally, a User Secrets file will be needed to provide local connection details.

This User Secrets file will look like the following:

{
    "Application": {
        "DataConnections": [
            {
                "Active": true,
                "ConnectTimeout": 30,
                "DataSourceName": "NorthWind_SQL",
                "Host": "localhost",
                "Password": "<DevUser password for SQL Server>",
                "Port": 1433,
                "UserName": "DevUser"
            },
            {
                "Active": false,
                "ConnectTimeout": 30,
                "DataSourceName": "NorthWind_Pgs",
                "Host": "localhost",
                "Password": "<DevUser password for PostgreSQL>",
                "Port": 5432,
                "UserName": "DevUser"
            }
        ],
        "OpenTelemetry": {
            "Server": "localhost",
            "Port": 4318
        }
    }
}

The User Secrets file is located at %APPDATA%\Microsoft\UserSecrets\<user_secrets_id>\secrets.json.

Configuration

The application configuration is broken into three files:

  • appsettings.json
  • appsettings.Development.json
  • appsettings.Production.json

This separation simplifies changing which data connection is active for a specific deployment and provides separated locations for sensitive values.

The data source values for Development are included in the local development config file, which can be found in the Web project:

  • appsettings.Development.json

The data source values for Production are included in the docker-deploy config files, as noted here:

  • SQL Server:
    • ..\docker\SqlServer\appsettings.Production.json
  • PostgreSQL:
    • ..\docker\PostgreSQL\appsettings.Production.json

Example configurations

appsettings.json
{
    "Application": {
        "DataSources": [
            {
                "Active": true,
                "DataSourceName": "NorthWind_SQL",
                "DataSource": "NorthWind",
                "DataSourceType": "SqlServer",
                "Schema": "dbo"
            },
            {
                "Active": true,
                "DataSourceName": "NorthWind_Pgs",
                "DataSource": "northwind",
                "DataSourceType": "PostgreSQL",
                "Schema": "pilot"
            }
        ],
        "OpenApi": {
            "Title": "PilotApiDotNet",
            "Contact": {
                "Email": "MikelLooper@gmail.com",
                "Name": "Michael Looper",
                "URL": "https://github.com/MikeLooper/PilotApiDotNet"
            },
            "Description": "A proof of concept API to explore best-practices and new ideas (.NET/C#)",
            "License": "MIT",
            "Summary": "Proof of concept API",
            "Version": "0.1.1"
        },
        "OpenTelemetry": {
            "Server": "otel-collector",
            "Port": 4318
        }
    },
    "Serilog": {
        "MinimumLevel": {
            "Default": "Information",
            "Override": {
                "Microsoft": "Warning",
                "Microsoft.AspNetCore.Hosting.Diagnostics": "Error",
                "Microsoft.Hosting.Lifetime": "Information",
                "System": "Warning"
            }
        },
        "WriteTo": [
            { "Name": "Console" },
            {
                "Name": "File",
                "Args": {
                    "path": "logs/log-.json",
                    "rollingInterval": "Day",
                    "rollOnFileSizeLimit": true,
                    "fileSizeLimitBytes": 104857600,
                    "retainedFileCountLimit": 14,
                    "formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
                }
            }
        ],
        "Enrich": [
            "FromLogContext",
            "WithMachineName",
            "WithProcessId",
            "WithThreadId",
            "WithExceptionDetails"
        ]
    },
    "AllowedHosts": "*"
}
appsettings_dataconnections.json
{
    "Application": {
        "DataConnections": [
            {
                "Active": true,
                "ConnectTimeout": 30,
                "DataSourceName": "NorthWind_SQL",
                "Host": "local_mssql",
                "Password": "<DevUser password>",
                "Port": 1433,
                "UserName": "DevUser"
            },
            {
                "Active": false,
                "ConnectTimeout": 30,
                "DataSourceName": "NorthWind_Pgs",
                "Host": "local_postgres",
                "Password": "<DevUser password>",
                "Port": 5432,
                "UserName": "DevUser"
            }
        ]
    }
}

The configuration that controls the application logic is in the "Application" section.

DataConnections

An array of data connections settings.

Active

Is the current section of settings active? Available options: true, false.

Within the DataConnections section, only one setting group can be active at one time.

ConnectTimeout

The number of seconds for the data source timeout.

DataSourceName

The name of the current data source section.

This name will match A DataSources.DataSourceName setting.

Host

The name of the host for the data source.

When running locally for development, this value would typically be "localhost".

When deployed to a Docker container, this value would typically be the name of the data source container.

Examples: "local_mssql", "local_postgres"

Password

The password for the user for the data source.

Port

The active port for the target data source.

UserName

The name of the user for the data source.

DataSources

The available data sources (such as a database).

Active

Is the current section of settings active? Available options: true, false.

DataSourceName

The name of the current data source section.

This name will match A DataConnections.DataSourceName setting.

DataSource

The name of the data source, such as a database name.

DataSourceType

The type of data source. Available values: "SqlServer", "PostgreSQL"

Schema

The schema where the target tables would be found.

OpenApi

The settings that control how the OpenAPI specification is define within the application.

These values will typically appear in an API UI or in an extracted OpenAPI specification.

Title

The API title.

Contact

A section of settings regarding who the point of contact is for this application.

Email

The email address of the contact person.

Name

The name of the contact person.

URL

A web address relating to the contact person.

Description

A description of this API.

License

The license relating to the source code for this application.

Summary

A summary of this API.

Version

The application version.

OpenTelemetry

The settings that control how OpenTelemetry (OTEL) is configured within the application.

Server

The OpenTelemetry server address.

Port

The OpenTelemetry server port.

Troubleshooting

Port Tracing

When troubleshooting OTEL, you can check for port usages, at the command line:

netstat -ano | findstr 4318

When working correctly, this will result in something similar to the following:

   Proto  Local Address          Foreign Address        State           PID
   ...
   TCP    0.0.0.0:4318           0.0.0.0:0              LISTENING       25384
   TCP    [::]:4318              [::]:0                 LISTENING       25384
   TCP    [::1]:4318             [::]:0                 LISTENING       46888
   TCP    [::1]:4318             [::1]:59028            TIME_WAIT       0
   ...

The, start the command (via Win+R) the resmon.exe application. Locate the PID, from the port listing, on the PID column.

Examples fro the above:

PID Application
25384 Docker Desktop Backend
46888 Windows Subsystem for Linux

Tracing Logging

You can also add tracing with this command, added to the PilotApi.Shared.OpenApi.Extensions.OpenTelemetryExtensions.OpenTelemetryWebApplicationBuilder(...) method.

OpenTelemetry.Sdk.SetDefaultTextMapPropagator(new TraceContextPropagator());

Deployment

This application will be deployed to a Docker container. Deploy instructions can be found in the Docker README.

Once deployed to Docker, the application will be accessible at https://localhost:55551/....

For Exmaple, the Categories endpoint for GetAll will be accessible at http://localhost:55551/categories/get-all.

Usage

The API contract for this project is defined in the OpenAPI specification file located at docs/openapi.yaml. You can use this file to generate client code or to explore the API using tools like Swagger UI or Bruno.

To get a visual representation of the API, you can use the Swagger editor by navigating to https://editor.swagger.io/.

You can also interact with the API using the Swagger UI by navigating to https://localhost:5001/swagger after running the application locally with Visual Studio.

(back to top)

Roadmap

  • API (.NET) version of the API (this code)
  • Java version of the API
  • Deploy API to Docker
  • Angular Frontend User Interface (UI) to consume APIs in Docker

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Top contributors:

contrib.rocks image

Copilot Customization

This repository uses two Copilot instruction layers:

  • Repository-wide guidance: .github/copilot-instructions.md
  • Unit-test-specific guidance: .github/instructions/unit-tests.instructions.md

How to use them:

  • The repository-wide file is intentionally minimal and applies across all work.
  • The unit-test file is scoped to test/**/*.cs and applies to unit test creation and maintenance tasks.
  • For unit test work, follow the NUnit and test-structure rules in the scoped instruction file.

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Michael Looper - MikelLooper@gmail.com

Project Link: https://github.com/MikeLooper/PilotApi

(back to top)

Acknowledgments

(back to top)

About

A proof of concept API to explore best-practices and new ideas (.NET/C#)

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages