.NET Conf 2019
.NET Core 3.0 launches at .NET Conf 2019 September 23-25, a free, virtual developer event.

ASP.NET Web APIs

Build secure REST APIs on any platform with C#

Get Started

REST APIs with .NET and C#

ASP.NET makes it easy to build services that reach a broad range of clients, including browsers and mobile devices.

With ASP.NET you use the same framework and patterns to build both web pages and services, side-by-side in the same project.

[ApiController]
public class PeopleController : ControllerBase 
{ 
    [HttpGet("people/all")] 
    public ActionResult<IEnumerable<Person>> GetAll()
    {
        return new []
        {
            new Person { Name = "Ana" },
            new Person { Name = "Felipe" },
            new Person { Name = "Emillia" }
        };
    }
}

public class Person
{
    public string Name { get; set; }
}
Command prompt
curl https://localhost:5001/people/all

[{"name":"Ana"},{"name":"Felipe"},{"name":"Emillia"}]

Simple serialization

ASP.NET was designed for modern web experiences. Endpoints automatically serialize your classes to properly formatted JSON out of the box. No special configuration is required. Of course, serialization can be customized for endpoints that have unique requirements.

Authentication and authorization

Secure API endpoints with built-in support for industry standard JSON Web Tokens (JWT). Policy-based authorization gives you the flexibility to define powerful access control rules—all in code.

Learn more about ASP.NET security

Command prompt
curl -H "Content-Type: application/json" -X POST -d "{'name':'Ana'}" https://localhost:5001/people/create -i

HTTP/2 202
[ApiController] 
public class PeopleApiController : ControllerBase 
{
    // Some code omitted for clarity

    [HttpGet("people/{id}")] 
    public ActionResult<Person> Get(int id) 
    { 
        var person = db.People.Find(id); 

        if (person == null) 
        { 
            return NotFound(); 
        } 

        return person; 
    } 

    [HttpPost("people/create")] 
    public IActionResult Create(Person person) 
    { 
        db.Add(person); 
        db.SaveChanges(); 
        return Accepted(); 
    } 
}

Routing alongside your code

ASP.NET lets you define routes and verbs inline with your code, using attributes. Data from the request path, query string, and request body are automatically bound to method parameters.

Learn more about routing in ASP.NET

HTTPS by default

You don't deploy your apps without security, so why test them without security? ASP.NET provides first class support for HTTPS out of the box. Automatically generate a test certificate and easily import it to enable local HTTPS so you run, and debug, your apps the way they are intended to be... secured.

Great tools for any platform

Build, debug, and deploy from any platform to any platform.

Issues in production? Not a problem... simply attach the debugger to your production instance and debug from your laptop!

Learn about .NET tools

Ready to Get Started?

Our step-by-step tutorial will help you get Web APIs with ASP.NET running on your computer.

Supported on Windows, Linux, and macOS

Get Started