Modern WebAPIS with ASP.NET Core

Modern WebAPIS with ASP.NET Core

Slides for my talk at the DWX 2018 in Nürnberg "Modern WebAPIs with ASP.NET Core"

Fb89953d3a1b1fcb862a186585c37c25?s=128

Fabian Gosebrink

June 25, 2018
Tweet

Transcript

  1. with Building modern WebAPIs ASP.NET Core

  2. None
  3. None
  4. None
  5. @FabianGosebrink

  6. None
  7. https://developer-academy.ch

  8. with Building modern WebAPIs ASP.NET Core

  9. What is ASP.NET Core?

  10. MVC + WebAPI + Web Pages

  11. None
  12. Faster Deployment Cycles

  13. None
  14. Tooling

  15. DOTNET CLI fabian gosebrink

  16. class Program { static void Main(string[] args) { Console.WriteLine("Hello World!");

    } }
  17. DOTNET CLI fabian gosebrink

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

    void Main(string[] args) 4. { 5. CreateWebHostBuilder(args).Build().Run(); 6. } 7. 8. public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 9. WebHost.CreateDefaultBuilder(args) 10. .UseStartup<Startup>(); 11. }
  19. public static IWebHostBuilder CreateDefaultBuilder(string[] args) { var builder = new

    WebHostBuilder(); builder.UseKestrel(...) .ConfigureAppConfiguration((hostingContext, config) => { config.AddJsonFile( "appsettings.json", optional: true, reloadOnChange: true); }) .ConfigureLogging((hostingContext, logging) => { logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); logging.AddConsole(); logging.AddDebug(); }) .ConfigureServices((hostingContext, services) => { //... }) .UseIISIntegration(); return builder; }
  20. Dependency Injection

  21. Startup.cs 1. public class Startup 2. { 3. public Startup(IConfiguration

    configuration) 4. { 5. Configuration = configuration; 6. } 7. 8. public IConfiguration Configuration { get; } 9. 10. public void ConfigureServices(IServiceCollection services) 11. { 12. services.AddOptions(); 13. 14. services.AddCors(...); 15.
  22. Kestrel

  23. None
  24. REST

  25. What is Rest?

  26. Rest is not WebAPI

  27. Rest is not HTTP

  28. None
  29. Architectural Style

  30. GET /api/orders/ GET /api/orders/1 POST /api/orders/ PUT /api/orders/1 DELETE /api/orders/1

  31. Rest Constraints

  32. Richardson Maturity Model

  33. STATUSCODES

  34. export const isSuccess = (status): boolean => (status >= 200

    && status < 300)
  35. 2xx

  36. 4xx

  37. 5xx

  38. 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 ActionResult<List<FoodItemDto>> Get() 13. { 14. ICollection<FoodItem> foodItems = _foodRepository.GetAll(); 15. IEnumerable<FoodItemDto> dtos = foodItems 16. .Select(x => Mapper.Map<FoodItemDto>(x)); 17. 18. return Ok(dtos);
  39. Documentation

  40. Documentation

  41. None
  42. VERSIONING

  43. document.docx

  44. document- nal.docx

  45. document- nal- nal.docx

  46. document-really- nal.docx

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

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

  49. document-really- nal- approved-by-customer- with-alterations- suggested-by-his- assistant.docx

  50. document-really- nal-approved- by-customer-with-alterations- suggested-by-his-assistant-and- his-friend-cause-apparently-he- thinks-he-knows-all-about-good- api-design

  51. document-really- nal-approved- by-customer-with-alterations- suggested-by-his-assistant-and- his-friend-cause-apparently-he- thinks-he-knows-all-about-good- api-design.docx

  52. None
  53. None
  54. DEMO

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

  56. /api/houses?orderby=Id

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

  58. HATEOAS

  59. { "departmentId": 10, "departmentName": "Administration", "locationId": 1700, "managerId": 200, "links":

    [ { "href": "10/employees", "rel": "employees", "type" : "GET" } ] }
  60. SignalR

  61. None
  62. None
  63. None
  64. Le Fin

  65. @FabianGosebrink https://offering.solutions/ fabian.gosebrink@offering.solutions https://github.com/FabianGosebrink https://github.com/FabianGosebrink/ASPNETCore- WebAPI-Sample

  66. Resources https://media.giphy.com/media/1BXa2alBjrCXC/giphy.gif http://img0.joyreactor.com/pics/post/photo-india-it-programmer-548432.jpeg