1. Home
  2. /
  3. Aspnet-core
  4. /
  5. ASP.NET Core Simple REST API

ASP.NET Core Simple REST API - Aspnet-core Typing CST Test

Loading…

ASP.NET Core Simple REST API — Aspnet-core Code

Demonstrates a simple ASP.NET Core Web API controller for managing Todo items.

// Controllers/TodoController.cs
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace WebApiExample.Controllers {
    [ApiController]
    [Route("api/[controller]")]
    public class TodoController : ControllerBase {
        private static List<Todo> todos = new List<Todo> {
            new Todo { Id = 1, Title = "Sample Task", Completed = false }
        };

        [HttpGet]
        public IEnumerable<Todo> Get() => todos;

        [HttpPost]
        public ActionResult<Todo> Post(Todo todo) {
            todo.Id = todos.Count + 1;
            todos.Add(todo);
            return CreatedAtAction(nameof(Get), new { id = todo.Id }, todo);
        }
    }

    public class Todo {
        public int Id { get; set; }
        public string Title { get; set; }
        public bool Completed { get; set; }
    }
}

Aspnet-core Language Guide

ASP.NET Core is a modern, cross-platform, high-performance framework for building web applications, APIs, microservices, and cloud-based applications using .NET. It unifies the previous ASP.NET frameworks into a single, modular platform.

Primary Use Cases

  • ▸Enterprise web applications
  • ▸RESTful APIs and microservices
  • ▸Cloud-native applications with Azure or AWS
  • ▸High-performance real-time applications (SignalR)
  • ▸Cross-platform web solutions

Notable Features

  • ▸Cross-platform and open-source
  • ▸High-performance Kestrel web server
  • ▸Unified framework for MVC, Razor Pages, Web API, and Blazor
  • ▸Middleware-based HTTP request pipeline
  • ▸Built-in dependency injection and configuration

Origin & Creator

Developed by Microsoft and initially released in 2016, ASP.NET Core represents a complete rewrite of ASP.NET to support cross-platform, modular, and high-performance web development.

Industrial Note

ASP.NET Core is often used in enterprise environments, cloud-native applications, and high-performance APIs where scalability, security, and maintainability are critical.

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher