Episode 1 - JSON API using ASP.NET Core, Docker & MongoDB
Tags: blog, howto, dotnetcore, beginners
Published: 2018-12-18 08:32:52

---
title: Episode 1 - JSON API using ASP.NET Core, Docker & MongoDB
published: true
tags: blog,how-to,dotnet-core,beginners
canonical_url: https://garfbradaz.github.io/blog/2018/12/18/Episode-1-json-api-dotnet-core-docker.html
published: true
cover_image: https://thepracticaldev.s3.amazonaws.com/i/abi2arzus9vlb8s6rp7p.PNG
series: ASP.NET Core Web API Episodes
---

## Inspiration

There is a series on [dev.to](https://dev.o) that I have followed by [Nathan Bland](https://dev.to/nathanabland) who has recorded as series of videos around creating a JSON API, using _Node.js_, _docker_ and _Express_.

I liked the idea around this, so I’m going to do the same, but in a blog style, but replacing _Node.js_ and _Express_ with _ASP.NET Core WebAPI_. I also want to use a MongoDB as a the backend.

## Set the Scene

The API itself will be for a _Book Shop Chain_ who want to expose their stores and titles via a public RESTful service for other companies to use. This can be used for stock lookups and to see which stores have stock available to sell.

Here are some example Epics to show the shape of the API needed:

> As a _book store_I can _add_ our _store_ to the database_So_ we can be accessible

> As a _book store_I can _add_ our _inventory_ to our database_So_ we can expose our inventory

> As a _book store_We can _update_ a books stock level_For_ an accurate stock level

> As a _API consumer_I can look up a _stores address__So_ we know where to buy a _book_

> As a _API consumer_I can look up a _book__So_ we can get a _list_ of _stores_ who sell a_book_

> As _book store IT Security_We can add _API Keys_ to the API_For_ API Consumers to use when querying the API

## What to expect

My plan is to release weekly blog posts covering in a similar fashion like Nathan’s:

- Setting up your .NET Core Project Structure.
- Setting up docker environment using docker-compose.
- Modelling API JSON back end using Mongo.
- Modelling API using Swagger.
- Unit Tests with Xunit.
- Integration Tests with Postman.
- Skeleton Book Store API (Routes etc).
- Skeleton Inventory API (Routes etc).
- Securing your API.
- Data validation.
- Pagination for large data queries.
- Filter and Search.
- Hooking up to Azure Dev Ops for Build and Release Pipeline.
- Publisher Swagger Documentation on Github.

I will post any code on Github as well.

## Start at Zero

So before starting cracking on with this, make sure your environment is set up. Because this is _.NET Core_, this is cross platform, so if you own a Mac or Linux box, feel free to join in. I’m going to be building this on a _Surface Book_, but I will try to be a good Xpat-Citizen and test across environments.

Please make sure the following is installed:

- [Dotnet Core](https://dotnet.microsoft.com/download) - I’m currently using 2.2.
- [Docker](https://www.docker.com/get-started) - You will need to also create a login for [Docker Hub](https://hub.docker.com/signup) if you do not have one.
- [Powershell Core](https://docs.microsoft.com/en-gb/powershell/scripting/overview?view=powershell-6) - PowerShell Core is cross-platform and runs on Windows, Linux, and MacOS while the old one runs on Windows only(CLI). There are options to install on the OS of choice.

We wont need to install Mongo as we will be running it using _Docker_.

## IDE

I will be using _Visual Studio Code_ for cross platform .NET Core support. I use a bunch of extension which I have put here:

[https://gist.github.com/garfbradaz/be010080df076d19892bf4ec71127b53](https://gist.github.com/garfbradaz/be010080df076d19892bf4ec71127b53)

You can import these using the following _Settings Sync_ extension on the marketplace:

[https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync](https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync)

If you already use _VSCode_, you may just want to find the _C#_, _Docker_ _GitLens_ and _.NET Core Test Explorer_ [extensions](https://code.visualstudio.com/docs/editor/extension-gallery).

**Note:** My list contains extensions like _Jekyll_ support which you wont need for this.

## Next time

We will create the _ASP.NET Core WebAPI_ template, set up the project structure. Join me next time!.