Skip to content

Create .NET Web API in Rider

Create .NET Web API

In Rider, go to File > New Solution.
Enter the solution name and select directory. For Target Framework, select .NET 8.0. For Template, select Web API. Create .NET Web API in Rider

There are multiple ways to run the project, at top right, press Run. alt text

Rider has a built-in Terminal accessible at bottom left or using Ctrl + Cmd + 1alt text

Or in Windows/MacOS Terminal, run
dotnet run


The browser containing Swagger will open alt text

Create BookController

Right click main folder and add a directory Controllers. alt text

Right click again to add a class/interface BookController.cs. alt text

The code should look like this

csharp
using Microsoft.AspNetCore.Mvc;

namespace Library.Controllers;

[ApiController]
[Route("[controller]")]
public class BookController : Controller
{
    [HttpGet]
    public IActionResult Index()
    {
        var book = new { Id = 1, Title = "Dotnet" };

        return Ok(book);
    }
}



Back in Program.cs, add these 2 lines

csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers(); //add this

//...

var app = builder.Build();

app.MapControllers(); //add this

//...


In Library.http, change the API to GET /book/


Run the project again and run Library.http to ensure it works. alt text

Released under the MIT License.