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

Building RESTFul APIs with ASP.NET Core by Fabian Gosebrink

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
PRO

October 20, 2017
Tweet

More Decks by Azure Zurich User Group

Other Decks in Programming

Transcript

  1. None
  2. None
  3. None
  4. with Building RESTFul APIs ASP.NET Core

  5. None
  6. None
  7. @FabianGosebrin

  8. None
  9. What is ASP.NET Core?

  10. MVC + WebAPI + Web Pages ASP.NET Core

  11. None
  12. Faster Deployment Cycles

  13. None
  14. Tooling

  15. Dependency Injection

  16. 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. }
  17. public class Program { public static void Main(string[] args) {

    var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); } }
  18. 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>();
  19. Kestrel

  20. None
  21. REST

  22. What is Rest?

  23. Rest is not WebAPI

  24. Rest is not HTTP

  25. None
  26. Architectural Style

  27. Rest Constraints

  28. Richardson Maturity Model

  29. None
  30. STATUSCODES

  31. GET /api/orders/ GET /api/orders/1

  32. 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
  33. Documentation SWAGGER

  34. None
  35. VERSIONING

  36. document.docx

  37. document- nal.docx

  38. document- nal- nal.docx

  39. document- really- nal.docx

  40. document- really- nal-end- of- discussion.docx

  41. document- really- nal- approved-by- customer.docx

  42. document- really- nal- approved-by- customer-with- alterations-

  43. document-really- nal-approved-by- customer-with- alterations- suggested-by-his- assistant-and-his- wife-cause-

  44. document-really- nal-approved-by- customer-with- alterations- suggested-by-his- assistant-and-his- wife-cause-

  45. None
  46. API-VERSION: 2.0 /API/V2/HOUSES

  47. DEMO

  48. /api/houses?page=4&pageSize=10

  49. /api/houses?orderby=Id

  50. /api/houses?fields=street,number

  51. SignalR

  52. None
  53. None
  54. None
  55. None
  56. Le Fin

  57. @FabianGosebrink https://swissangular.com https://github.com/FabianGosebrink https://github.com/FabianGosebrink WebAPI-Sample

  58. Resources https://www.thefamouspeople.com/pro les/images/og-donald_trump_ ag.jpg https://timedotcom. les.wordpress.com/2017/07/gettyimages-810247620.jpg?w=720&quality=85 https://media.giphy.com/media/xUPOqFfyBzvODVNTNu/giphy.gif https://cdn.vox- cdn.com/thumbor/5BOvGGpVyW4hSPLTAEYvHng6JlQ=/0x0:2931x1649/1200x800/ lters:focal(1239x265:1707x733)/cdn.vox

    cdn.com/uploads/chorus_image/image/55610995/GettyImages_810247620.0.jpg https://media.giphy.com/media/1BXa2alBjrCXC/giphy.gif http://img0.joyreactor.com/pics/post/photo-india-it-programmer-548432.jpeg