Skip to content

An example of a .NET REST API. Created with love using .NET Core 3.1, postgreSQL and Docker.

License

Notifications You must be signed in to change notification settings

rolandhemmer/dotnet-rest-api-example

Repository files navigation

.NET REST API Example

An example of a .NET REST API (with database)

Table of contents

  1. Prerequisites
  2. Environment
    2.1. Docker
    2.2. .NET Core SDK
  3. Usage

1. Prerequisites

⬆ back to top

2. Environment

2.1. Docker

The official Docker documentation is simply wonderful. Follow the steps, and everything should be as smooth as possible.

Make sure to read the "OS requirements" part first. Not all Linux distrubtions are properly supported. Also, LTS versions are usually highly recommanded.

Once ready, Docker Compose is the next step. Please note that even if there's lot of differents installation options, the Python package is often the preferred option (for its ease-of-use and easy upgradability):

pip3 install docker-compose

⚠ This command might conflit with your existing Python installation. In that case, other installation ways should be preferred.

Use the following commands to make sure everything is correctly installed:

docker --version
docker-compose --version

⬆ back to top

2.1.1 Additional Windows configuration

After Docker and Docker Compose, a Windows installation might require a little bit more of work: using the Windows Subsystem for Linux.

The Windows Subsystem for Linux lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a virtual machine.

Use the previous link to get started with this truly life-changing Windows feature.

Then, follow these few configuration steps to connect your new Linux terminal to Docker:

  • Expose the Docker deamon without TLS:
  • Share your disk drives to Docker:
  • Install Docker on your Linux subsystem (see 2.1. Docker)
  • Connect your Linux installation to your Windows Docker instance:
export DOCKER_HOST=tcp://localhost:2375

# To avoid entering this line at every shell launch, add it to your .profile, .bashrc or your preferred shell startup configuration.
  • Finally, create the Linux file /etc/wsl.conf (as sudo), and enter this content:
[automount]
root = /
options = "metadata"

This will change your Windows disk mount point from /mnt/<disk_letter> to /<disk_letter> (i.e: /mnt/c to /c).

Several system reboots might be required for some steps.

⬆ back to top

2.2. .NET Core SDK

The official .NET Core documentation is also very detailled. Use the radio menu below the title to choose your OS.

Use the following commands to make sure everything is correctly installed:

dotnet --version

⬆ back to top

3. Usage

The repository is Docker-based: from a clean installation, simply run docker-compose up to build and run the sample API.

Default port is 8080.

3.1. Run options

Docker compose supports various options and arguments.
See the compose documentation for more.

⬆ back to top