Best way to spin up a React plus ASP.NET Core Web API Application?

Published on

Looking to create a React front-end with an ASP.NET Core back-end? You have two clear options.

  1. Use the dotnet React templates
  2. Spin up separate projects for front-end and back-end

Option 1 (dotnet React templates)

This option will create a single project containing both the Web API back-end and React front-end.

All it takes is a simple command.

Terminal window
dotnet new react

(Or you can achieve the same result using Visual Studio).

So long as you’re using the latest version of the templates and targeting ASP.NET Core 2.1 (or above) this will create a single project with two parts.

  1. A standard Create-React-App front-end (found in the ClientApp folder)
  2. A standard ASP.NET Core Web API

Pros

Cons

Option 2 (separate React and Web API projects)

This requires two steps.

First spin up a new Web API project.

Terminal window
dotnet new api

(or use the Visual Studio “new project” wizard).

And separately create a React application.

Terminal window
npx create-react-app <app-name>

Or if you fancy using Typescript…

Terminal window
npx create-react-app <app-name> --typescript

This way you’ll end up with two separate projects, a Web API…

And separate React app (using Typescript in this case).

Pros

Cons

Really, they’re pretty similar

Since MS adopted the official create-react-app templates for ASP.NET 2.1, the gap between the two options has shrunk quite a bit.

It really comes down to personal preference.

Either option is viable; the React app you end up with will be the same in either case.

In summary, it’s probably more important to pick one and get on with building your app than to spend too much time deciding between them!

Next Up
  1. Different js scripts for different ASP.NET core environments
  2. Add React.js to your existing asp.net application
  3. Cross-Origin Request Blocked