Best way to spin up a React plus ASP.NET Core Web API Application?
Tags: aspnetcore, react
Published: 2018-11-23 16:04:21

---
title: Best way to spin up a React plus ASP.NET Core Web API Application?
published: true
tags: aspnetcore, reactjs
canonical_url: https://jonhilton.net/create-react-application-with-aspnet-core-web-api/
cover_image: https://jonhilton.net//img/core-and-react-new-project.png
---

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.

``` powershell
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

![](/img/2018-11-19-best-way-to-spin-up-a-react-plus-webapi-application/2018-11-19-20-04-36.png)

### Pros
* Probably the easiest option if you're just starting out
* Less context-switching as you work on both parts of the app
* The front-end React part is "standard" (the same as any other React app created using the "Create React App" templates)
* The template includes some sample code showing one way to make back-end calls from the front-end application
  
### Cons
* Everything in one folder making it harder so separate the two parts of the application (for deployment etc.)
* Anyone wanting to work on either just the front-end or just the back-end will still have access to the other part of the application


## Option 2 (separate React and Web API projects)

This requires two steps.

First spin up a new Web API project.

``` powershell
dotnet new api
```

(or use the Visual Studio "new project" wizard).

And separately create a React application.

``` powershell
npx create-react-app <app-name>
```

Or if you fancy using Typescript...

``` powershell
npx create-react-app <app-name> --typescript
```

This way you'll end up with two separate projects, a Web API...

![](/img/2018-11-19-best-way-to-spin-up-a-react-plus-webapi-application/2018-11-19-20-13-55.png)

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

![](/img/2018-11-19-best-way-to-spin-up-a-react-plus-webapi-application/2018-11-19-20-14-24.png)

### Pros
* Separation of concerns
* Different people/teams can work on each part (front-end/back-end) without treading on each other's toes
* You can specify Typescript when you spin up the React app
* Each part of the app can be deployed separately, stored in different Git repositories etc.

### Cons
* More context-switching if you're building "full-stack" features (jumping between front-end/back-end)
* You'll likely need to spin up two instances of your IDE/code editors to run the application (the other option runs both with CTRL+F5)

## 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!

[Want to get these articles first? Click here to have me email them to you :-)](https://jonhilton.net/devto/next-react-post/)