Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building RESTFul APIs with ASP.NET Core by Fabi...

Building RESTFul APIs with ASP.NET Core by Fabian Gosebrink

Modern REST-APIs are at the core of today's technology and distributed systems. In this session, Fabian explains how universal cross platform web APIs are built using the latest .NET Core technologies. After an introduction to the principles of REST, we dive into the technical details and explore how ASP.NET Core & Visual Studio 2017 are used to build the APIs of tomorrow.

About the speaker:

Fabian Gosebrink is a Microsoft MVP and a passionate web developer using ASP.NET/ASP.NET Core and AngularJS/Angular. He supports enterprise customers as a professional full stack software engineer, consultant and trainer. He is a speaker at international conferences, the founder of .NET-Day Switzerland, Offering Solutions Software and Co-founder of SwissAngular (www.swissangular.com). He is very active in the community and is an administrator of the largest German C#-Community, www.mycsharp.de.

Azure Zurich User Group

October 20, 2017
Tweet

More Decks by Azure Zurich User Group

Other Decks in Programming

Transcript

  1. Program.cs 1. public class Program 2. { 3. public static

    void Main(string[] args) 4. { 5. BuildWebHost(args).Run(); 6. } 7. 8. public static IWebHost BuildWebHost(string[] args) => 9. WebHost.CreateDefaultBuilder(args) 10. .UseStartup<Startup>() 11. .Build(); 12. }
  2. public class Program { public static void Main(string[] args) {

    var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); } }
  3. Startup.cs 1. public class Startup 2. { 3. public Startup(IConfiguration

    configuration) 4. { 5. Configuration = configuration; 6. } 7. 8. public IConfiguration Configuration { get; set; } 9. 10. public void ConfigureServices(IServiceCollection services) 11. { 12. services.AddOptions(); 13. services.AddCors(...); 14. 15. services.AddSingleton<IFoodRepository, FoodRepository>();
  4. The Controller 1. [Route("api/[controller]")] 2. public class FoodController : Controller

    3. { 4. private readonly IFoodRepository _foodRepository; 5. 6. public FoodController(IFoodRepository foodRepository) 7. { 8. _foodRepository = foodRepository; 9. } 10. 11. [HttpGet] 12. public IActionResult Get() 13. { 14. ICollection<FoodItem> foodItems = _foodRepository.GetAll(); 15. IEnumerable<FoodItemDto> dtos = foodItems