web api quick start how to quickly maximize the value you add with web api

18
Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Upload: laureen-stokes

Post on 17-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Web API Quick StartHOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Page 2: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

BRONZE

SILVER

CODE CAMP 2013 SPONSORS

GOLD

Page 3: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Goal To allow programmers experienced with creating services in the Microsoft stack to quickly get going with Web API

Page 5: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Agenda◦ Background and Motivations◦ Quick Start◦ Dealing with Mismatched Conventions◦ Versioning◦ Documenting Our API

Page 6: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Background and MotivationsAPI MODELING - RPC

ROUTE ACTION VERB ARGUMENTS

\AccountManager\GetAccounts Get all accounts GET none

\AccountManager\GetAccounts\:id Get account by ID GET query string

\AccountManager\AddAccount Add account POST header

\AccountManager\UpdateAccount Update account POST header

\AccountManager\DeleteAccount Delete account POST query string

\AccountManager\Deposit Deposit funds POST header

\AccountManager\Withdraw Withdraw funds POST header

Page 7: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Background and MotivationsAPI MODELING – RESOURCE CENTRIC

ROUTE ACTION VERB ARGUMENTS

\Accounts Get all accounts GET none

\Accounts\:id Get account by ID GET query string

\Accounts Add account POST header

\Accounts\:id Update account PUT header

\Accounts\:id Delete account DELETE header

\Accounts\:id\Deposit Deposit funds POST header and query string

\Accounts\:id\Witdraw Withdraw funds POST header and query string

Page 8: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Background and MotivationsEVOLVING FRAMEWORKS

◦ ASP◦ ASP.Net Web Forms

◦ Server side controls◦ Disconnected data access◦ Data binding

◦ ASP.Net MVC◦ Separation of Concerns◦ Closer to the metal with HTTP

◦ ASP.Net Web API◦ Content negotiation◦ Fewer global objects

◦ Improved testability◦ Integrated help page support◦ Symmetrical client programming model◦ Better HTTP support via strongly typed

HTTP Object Model◦ Filter chaining (or filter pipeline) support◦ Self-hosting

Page 9: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Background and MotivationsEVOLVING DESIGNS

◦ ASP◦ Weak support for server side UX logic

◦ ASP.Net Web Forms◦ Stronger support for server side UX logic◦ Weak support for loosely coupled UX tier

◦ ASP.Net MVC◦ Stronger support for looser coupling UX

tier◦ Weak support for resource centric API

modeling

◦ ASP.Net Web API◦ Stronger support for resource centric API

Modeling

Page 10: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Background and MotivationsASP.NET MVC RPC STYLE JSON SERVICES

◦ Not resource centric◦ Not good for multi-targeting

Page 11: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Background and MotivationsASP.NET MVC RPC STYLE JSON SERVICES - API

ROUTE ACTION VERB ARGUMENTS

\AccountManager\GetAccounts Get all accounts GET none

\AccountManager\GetAccounts\:id Get account by ID GET query string

\AccountManager\AddAccount Add account POST header

\AccountManager\UpdateAccount Update account POST header

\AccountManager\DeleteAccount Delete account POST query string

\AccountManager\Deposit Deposit funds POST header

\AccountManager\Withdraw Withdraw funds POST header

Page 12: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Background and MotivationsASP.NET MVC RPC STYLE JSON SERVICES - ISSUES

◦ Not resource centric◦ Not good for multi-targeting or for public facing API

Page 13: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Background and MotivationsASP.NET MVC RESOURCE CENTRIC STYLE JSON SERVICES - API

ROUTE ACTION VERB ARGUMENTS

\Accounts Get all accounts GET none

\Accounts\:id Get account by ID GET query string

\Accounts Add account POST header

\Accounts\:id Update account PUT header and query string

\Accounts\:id Delete account DELETE query string

\Accounts\:id\Deposit Deposit funds POST header and query string

\Accounts\:id\Witdraw Withdraw funds POST header and query string

Page 14: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Background and MotivationsASP.NET MVC RESOURCE CENTRIC STYLE JSON SERVICES

◦ Resource centric◦ Cumbersome to write

◦ Awkward routing◦ Difficult to organize controller◦ Requires extra code for content negotiation◦ Magic strings for status codes

Page 15: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Quick StartWEB API DEMO

Page 16: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Quick StartASP.NET WEB API RESOURCE CENTRIC STYLE JSON SERVICES - API

ROUTE ACTION VERB ARGUMENTS

\Accounts Get all accounts GET none

\Accounts\:id Get account by ID GET query string

\Accounts Add account POST header

\Accounts\:id Update account PUT header

\Accounts\:id Delete account DELETE header

\Accounts\:id\Deposit Deposit funds POST header and query string

\Accounts\:id\Witdraw Withdraw funds POST header and query string

Page 17: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Take Aways◦ Web Api makes it easier to create HTML friendly web services◦ Json.Net serializer allows offers a lot of benefits for making HTML friendly JSON◦ Help Pages allows you to get your services documented quickly◦ There are a few options for versioning your services, the most important thing is to pick one

Page 18: Web API Quick Start HOW TO QUICKLY MAXIMIZE THE VALUE YOU ADD WITH WEB API

Resources◦Web API Official Page http://www.asp.net/web-api ◦APIGEE http://apigee.com/about/ ◦Pluralsight http://www.pluralsight.com/ ◦My Blog http://www.RyanVice.net