This repository, reference-architecture-api
, is a core component of an overall reference architecture that I promote for building secure enterprise and Internet-scale web applications. The is API repository can be used as a template to build microservices in an efficient and repeatable way. There is no need to reinvent the wheel and many best practices are already baked into this solution.
This example API is built on the .NET Core and is cross platform compatiable. It can run locally on any platform that can host .NET Core and is specifically implemented to run within Linux-based Docker containers.
The following steps will quickly get you up and running and testing this API.
- Install the dependencies (details below)
- Fork the repository
- Clone the forked repository
- Run the build and test commands
dotnet restore dotnet build
- Manually run the unit and integration tests
dotnet test
- Run the application
dotnet run -p src/Infrastructure.WebApi/
- Manually test the application
curl http://localhost:5000/api/ping
Or you can just copy and paste the above URL your browsers address bar.
If you experience errors, it is likely that you do not have all of the requisite dependencies installed. Please ensure that you do. Follow the instructions, below.
If it turns out that you do have all of the dependencies installed and you are still experiencing errors, please create a new Issue.
There are a number of depenedencies that must be installed locally on your development machine in order to get this application to build and run. The dependencies are detailed below, along with direct links that you can use to download them.
The following table lists the absolute minimum requirements for building and running the reference API.
Dependency | Description |
---|---|
.Net CLI | Command-Line Interface tool needed to compile and run the source code |
MongoDB | Running database required to execute the application or tests in the local environment. |
Docker | Must be installed and running in order to run the application entirely in Docker containers |
Install Git SCM for your given platform. This will install the git bash command-line tool that has all of the environment variables arleady configured. There is also an option to install the environment variables for use with the standard Windows command-line or OSX Terminal.
Though they are not required, it may also be useful to install GitHub for Windows or GitHub for Mac.
You will want to install the dotnet-cli and associated tools. The build script used in this repository have a dependency on the .NET command-line tools.
There are a couple of different options for satisfying the MongoDB requirement.
- You can download the MongoDB binaries and install directly onto your local development machine.
- You can downlaod the official MongoDB Docker image and run that locally.
- You can use a hosted docker service, like mLab or Azure's CosmoDB.
You will need to install Docker on your local development machine.
- Install Docker for Windows
- Install Docker for Mac
Navigate in your browswer to the reference-architecture-api repository. https://github.com/walterpinson/reference-architecture-api
Follow the GitHub instructions for Forking a Repository.
Navigate to your fork of the reference-architecture-api repository. Follow the GitHub instructions for Cloning a Repository.
You can manually build the API on your local host by running the following commands in a git-bash window, terminal window, or Windows command-line window after switching to the repository root directory.
dotnet restore
dotnet build
If you want to run the unit tests and the integration tests, issue the following commnand.
dotnet test
If you want to launch the API on your local host, issue the following command.
dotnet run
The dotnet command-line interface documentation is quite useful for those looking for command-line mastery.
There are a number of scripts that can be used to expedite each aspect of the manual build process or tie them all together in order to get the application running in a Docker container.
sh/runstack.sh
This command runs the API and the supporting MongoDb database server as Docker service stack.
sh/run.sh
NOTE: This approach still requires a running MongoDb database in the local environment.
This command deletes any existing containers, and rebuilds the source, rebuilds the docker image, and reruns the container. This is your go-to command. When you make some code changes and you want your running docker container to reflect those code changes, this is is the command that you run.
sh/build_app.sh
sh/build_image.sh
sh/build_container.sh
You can find further documentation detailing the concepts behind this reference architecture in the reference-architecture-api Wiki.