Building HTTP services for modern client apps

Slides:



Advertisements
Similar presentations
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

Background REST (Representational State Transfer) What does it mean to be RESTful? Why REST? WCF How does WCF support REST? What are the pieces we need.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Windows 8 (1) (2) (3) Windows 8 (1) (2) (3)
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Feature: Purchase Requisitions - Requester © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Building Web APIs in Windows Azure Name Title Microsoft Corporation.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
.NET Framework V3.5+ & RESTful web services Mike Taulty Developer & Platform Group Microsoft Ltd
Co- location Mass Market Managed Hosting ISV Hosting.
06 | Implementing Web APIs Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek.
Jon Flanders INT303. About Me  Jon Flanders –  Independent consultant/trainer  BizTalk MVP.
Windows 7 Training Microsoft Confidential. Windows ® 7 Compatibility Version Checking.
Feature: Purchase Order Prepayments II © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: Web Client Keyboard Shortcuts © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
 Rico Mariani Architect Microsoft Corporation.
Windows 8 (1) (2) (3) Windows 8 (1) (2) (3)
ASP.NET Web API Udaiappa Ramachandran NHDN-Nashua.NET/Cloud Computing UG Lead Blog:
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Print Remaining Documents © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Connect with life Connect with life
NEXT: Overview – Sharing skills & code.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Document Attachment –Replace OLE Notes © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: Employee Self Service Timecard Entry © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

customer.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
06 | HTTP Services with Web API Bruno Terkaly | Technical Evangelist Bret Stateham | Technical Evangelist.
demo Demo.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
The CLR CoreCLRCoreCLR © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

Возможности Excel 2010, о которых следует знать
Adventures in Haacking
Microsoft Build /11/2018 2:12 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
Building Modern Web Apps with ASP.NET MVC 6
Driving Experiences via Services Using the Microsoft .NET Framework
Title of Presentation 11/22/2018 3:34 PM
Baseline: How Are We Doing Now?
Accessing Data in a .NET Web Application
Office Mac /30/2018 © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Title of Presentation 12/2/2018 3:48 PM
MIX 09 12/9/2018 6:08 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Building HTTP Services with ASP.NET Web API
The OpenRasta framework for building RESTful applications
Maxim Lukiyanov Program Manager Microsoft Corporation
Silverlight Debugging
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
4/27/17, Bell #8 What amount of net pay has been earned this period?
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
PENSACOLA ENERGY WORK PLAN OCTOBER 10, 2016
Title of Presentation 5/12/ :53 PM
Шитманов Дархан Қаражанұлы Тарих пәнінің
Title of Presentation 5/24/2019 1:26 PM
5/24/2019 6:44 PM 1/8/18 Bell #10 In a world governed by the gods, is there any room for human will? Do human choices make a difference? EXPLAIN © 2007.
日本初公開!? Vista の新機能を実演 とっちゃん わんくま同盟 7/23/2019 9:09 AM
Title of Presentation 7/24/2019 8:53 PM
7/19/2019 2:53 AM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Erik Porter Program Manager ASP.NET Microsoft Corporation
Presentation transcript:

Building HTTP services for modern client apps Filip Wojcieszyn

@filip_woj www.strathweb.com www.arcmedia.ch

HTTP

Everywhere! Source: Cisco, 2013, http://newsroom.cisco.com/feature-content?type=webcontent&articleId=1208342

What do you need? Maintainability Discoverability Scalability Versioning, debugging Discoverability RESTful routing, straightforward documentation Scalability Asynchronous pipeline Flexibility Customize all the things

ASP.NET Web API overview 10’ Building an API 30’ Media types 10’ Rich querying capabilities 10’

ASP.NET WEB API

Overview New Microsoft framework. (August 2012, Version 2 October 2013) for building HTTP services & applications HTTP as a first class citizen in .NET - Aimed at simplyfing and standardizing HTTP area on the MS stack (see: WCF / ASMX / MVC / HttpHandlers) - HTTP as a fully fledged *application* protocol Open source

New HTTP object model Strongly typed HTTP concepts. HttpRequestMessage, HttpResponseMessage, Headers, HttpContent No «angle brackets coding» or «magic strings» Code based configuration only Symmetry between client and server Asynchronous APIs

“ASP.NET” “Web API” ASP.NET Web API it doesn't require neither ASP.NET, nor IIS to run Web API it's an HTTP framework, that can do much more than "just" API

Hosting Web. Self hosting. In Memory. ASP.NET & IIS Self hosting. Any .NET application can become a Web API server In Memory. Whole pipeline in memory OWIN (Open Web Interface for .NET). Decouple web application from the host.

Building an API

API with ASP.NET Web API Create a controller. Add actions. Add routes. ApiController, IHttpController Add actions. Return models / HttpResponseMessage / IHttpActionResult Add routes. Centralized or attribute-based Use message handlers / filters. Cross-cutting concerns

Controllers Represents a HTTP resource Doesn’t have to map 1-to-1 to an entity! ApiController provides lots of helpers Helps you conform to HTTP standards Can be loaded from other assemblies Use IAssembliesResolver

Don’t /api/GetTeams /api/GetTeam?id=1 /api/GetPlayersByTeam?id=1 /api/AddTeam /api/UpdateTeam /api/DeleteTeam?id=1

Do GET /api/teams GET /api/teams/1 GET /api/teams/1/players POST /api/teams PUT /api/teams/1 DELETE /api/teams/1

Actions Actions handle HTTP request HTTP verb dispatching (RESTful) Maps to an incoming HTTP request HTTP verb dispatching (RESTful) Actions matched: - by prefix (GetAll, GetById) - by action attribute (i.e. [HttpPost]) RPC not encouraged, but supported

Actions parameters From URI - primitives From Body - complex types Int, string etc From querystring or route data From Body - complex types Use MediaTypeFormatters Only one thing can be read from body Customizable [FromUri], [FromBody], custom parameter binding

Action return Model / void HttpResponseMessage IHttpActionResult Any CLR type HttpResponseMessage Work with HTTP concepts directly IHttpActionResult Predefined factories creating HttpResponseMessage public interface IHttpActionResult { Task<System.Net.Http.HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken); }

Routing Attribute routing (Web Api 2) Centralized Customizable Easy to enable hierarchical, complex routing. Centralized Traditional approach known from ASP.NET Customizable Constraints, defaults

Message handlers Run first/last in the pipeline Chained Raw HttpRequestMessage / HttpResponseMessage Can short-circuit the response Cross-cutting concerns Logging, authentication

Message handlers Run first and last in the pipeline Chained Raw HttpRequestMessage / HttpResponseMessage Can short-circuit the response Cross-cutting concerns Logging, authentication

Media types

Content negotiation Determining the media type of a response Client and server engage in a “negotiation process” I.e. application/json or image/png Same entity can be represented in various formats JSON (application/json), XML (text/xml), CSV (text/csv), binary (application/octet-stream) and many more Part of HTTP spec RFC 2616, section 12

Content negotiation in Web API 1. MediaTypeMapping /api/resource.json, /api/resource?format=json 2. Accept header Accept: application/json 3. Content-type header Content-type: text/xml 4. MediaTypeFormatter order Can be configured to return 406 (Not acceptable)

Content negotiation in Web API JSON Uses JSON.NET or DataContractSerializer XML Uses DataContractSerializer or XmlSerializer Pluggable Many other media types can be supported Conneg can be run by hand Using IContentNegotiatior

OData

OData OData V3 Protocol Expose an endpoint as IQueryable Atom format / JSON light Expose an endpoint as IQueryable Client has great freedom in terms of querying capabilities $top, $skip, $orderby, $filter Similar as the correspdonding LINQ operators $expand, $select, $value Support lazy loading and partial retrieval of entites

Extras

Extras Document your API easily Logging WebApiContrib Use the HelpPage functionality or raw IApiExplorer Logging See what’s happening inside with ITraceWriter WebApiContrib Don’t reinvent the wheel, it’s all there for you! Try out nightlies http://www.myget.org/F/aspnetwebstacknightly/

1/18/2019 8:29 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.