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

RESTful APIs in ASP.NET Core

RESTful APIs in ASP.NET Core

APIs are everywhere, in fact; for most things today one could say “there’s an API for that”. Microsoft’s ASP.NET Core is a brand new web framework, completely open sourced and cross platform; for building scalable- & cloud ready web applications.

In this interactive talk we go on a journey to discover some of the features ASP.NET Core offers for building practical RESTful APIs like Logging, Middleware, Routing, Configuration, Dependency Injection, Hosting and Servers. All hands on deck, it’s going to get messy!

Fanie Reynders

March 17, 2017
Tweet

More Decks by Fanie Reynders

Other Decks in Programming

Transcript

  1. “ An Application Programming Interface is a protocol intended to

    be used as an interface by software components to communicate with each other.
  2. “ Representational State Transfer is a style of architecture based

    on a set of principles that describe how networked resources are defined and addressed
  3. .NET Framework 4.6 Full .NET Framework .NET Core 1.x Modular

    libraries & runtime Optimized for server & cloud ASP.NET 4.6 System.Web ASP.NET Core 1.x Web Forms MVC Web API MVC Web Pages
  4. public class Program { public static void Main(string[] args) {

    var host = new WebHostBuilder() .UseKestrel() .Configure(app => app.Run(async context => await context.Response.WriteAsync("Hello World!"))) .Build(); host.Run(); } }
  5. Request Response Kestrel Middleware 1 Middleware 2 Middleware 3 Middleware

    1 Middleware 2 Middleware 3 Middleware 1 Middleware 2 ASP.NET Core Middleware
  6. GET • Accept: • application/json • text/csv • /profiles •

    /profiles?{name} • /profiles/{id} • /profiles/{id}/friends POST • Accept: • application/json • /profiles • { … } PUT • Accept: • application/json • /profiles/{id} • { … } DELETE • Accept: • application/json • /profiles/{id}
  7. “ HATEOAS is a constraint of the REST stateless application

    which allows a REST client to have no prior knowledge about how to interact with the server beyond a generic understanding of hypermedia provided by the API.
  8. GET /people/2 HTTP/1.1 Host: api.awesome.io Accept: application/json { "_links": [

    { "rel": "self", "href": "http://api.awesome.io/people/2" }, { "rel": "update-person", "href": "http://api.awesome.io/people/2", "method": "PUT" }, { "rel": "remove-person", "href": "http://api.awesome.io/people/2", "method": "DELETE" } ], "name": "Joe", "surname": "Soap" }
  9. GET /languages HTTP/1.1 Host: api.awesome.io Accept: application/json HTTP/1.1 200 OK

    Content-Type: application/json Cache-Control: max-age=3600 Content-Length: 88 Etag: "6d82cbb050ddc7fa9cbb659014546e59" { "languageCodes": [ {"da":"Danish"}, {"no":"Norwegian"}, {"en":"English"} ] }