GIDS13 - Building Service for Any Clients
Upcoming SlideShare
Loading in...5
×
 

GIDS13 - Building Service for Any Clients

on

  • 601 views

My Great Indian Developer Summit 2013 talk on "Building Service for Any Clients using Web API". In this session i give a introduction to Web API and how to create a Web API.

My Great Indian Developer Summit 2013 talk on "Building Service for Any Clients using Web API". In this session i give a introduction to Web API and how to create a Web API.

Statistics

Views

Total Views
601
Views on SlideShare
416
Embed Views
185

Actions

Likes
0
Downloads
3
Comments
1

5 Embeds 185

http://www.kashyapas.com 171
http://feeds.feedburner.com 7
http://feeds2.feedburner.com 5
http://newsblur.com 1
http://feedreader.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Lohit,

    I was dis-appointed by the slide deck, it is a full copy paste from channel 9 video presentation by James Chanmbers

    Please dont copy and duplicate the content....
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Michael
  • Telerik truly is an end to end provider of tools for developers

GIDS13 - Building Service for Any Clients GIDS13 - Building Service for Any Clients Presentation Transcript

  • Building Service for Any ClientsLohith G NTelerik
  • ABOUT ME• Developer Evangelist, Telerik India• Microsoft MVP• @kashyapa• Lohith.Nagaraj@telerik.com• www.Kashyapas.com• www.Telerikhelper.net
  • Telerik at a Glance• Established in 2002• Telerik is now a leading vendor of productivity tools & solutions• 11 global offices, 700+ people, 100,000+ loyal customers in over 90 countries• 880,000 Registered users in the Telerik Online Community• True global vendor – no vertical or geographical focus• Numerous business awards, hundreds of technology awards““Deliver More ThanDeliver More ThanExpected”Expected”
  • End to End ProviderSolutions for all aspects of Software DevelopmentAutomated Functional & PerformanceUI TestingUnit TestingLoad/Stress TestingExploratry TestingTestingRequirements GatheringProject ManagementDefect ManagementTeam and Customer CollaborationPlanningMulti-platform UI toolsCode quality and performance toolsData access and reporting toolsConstruction
  • Telerik Product PortfolioPlanPlan BuildBuild TestTest DeliverDeliverAGILE PROJECTAGILE PROJECTMANAGEMENTMANAGEMENTDEVELOPER TOOLSDEVELOPER TOOLS QUALITY ASSURANCEQUALITY ASSURANCETOOLSTOOLSWEB PRESENCEWEB PRESENCEPLATFORMPLATFORMWindows Phone*SitefinityOpenAccess ORMSilverlightWinFormsReportingJustCodeWPF ControlsASP.NET MVCJustMockASP.NET AJAX*JustDecompileTeamPulseWindows 8*TestStudio
  • Agenda• How does ASP.NET Web API fit in?• Introduction to Web API• Consuming Web API from jQuery• Consuming Web API from Windows 8
  • Web API is part of ASP.NETASP.NET Core
  • WHERE CAN YOU GET WEBAPI
  • www.asp.net/web-api
  • Building a read only Web API
  • Sample Read-only Model andControllerpublic class Personpublic class Person{{public int Id { get; set; }public int Id { get; set; }public string Name { get; set; }public string Name { get; set; }}}Step 1:Create a Modelpublic class PersonController : ApiControllerpublic class PersonController : ApiController{{List<Person> _people;List<Person> _people;public PersonController()public PersonController(){{_people = new List<Person>();_people = new List<Person>();_people.AddRange(new Person[]_people.AddRange(new Person[]{{new Person { Id = 1, Name = "Chucknew Person { Id = 1, Name = "ChuckNorris" },Norris" },new Person { Id = 2, Name = "Davidnew Person { Id = 2, Name = "DavidCarradine" },Carradine" },new Person { Id = 3, Name = "Brucenew Person { Id = 3, Name = "BruceLee" }Lee" }});});}}}}Step 2:Make an API Controller
  • Read-only Controller Actions toreturn data// GET /api/person// GET /api/personpublic IEnumerable<Person> Get()public IEnumerable<Person> Get(){{return _people;return _people;}}Step 3:Return everything// GET /api/person/5// GET /api/person/5public Person Get(int id)public Person Get(int id){{return _people.First(x => x.Id ==return _people.First(x => x.Id ==id);id);}}Step 4:Return one item
  • Routing a Web API UsingGlobal.asax.cspublic static voidpublic static voidRegisterRoutes(RouteCollectionRegisterRoutes(RouteCollectionroutes)routes){{routes.MapHttpRoute(routes.MapHttpRoute(name: "DefaultApi",name: "DefaultApi",routeTemplate: "api/routeTemplate: "api/{controller}/{id}",{controller}/{id}",defaults: new { id =defaults: new { id =RouteParameter.Optional }RouteParameter.Optional }););}}Routing:Familiar syntax,conventional approach
  • Manipulating HTTP Responses// GET /api/person/5// GET /api/person/5public HttpResponseMessage<Person> Get(int id)public HttpResponseMessage<Person> Get(int id){{trytry{{var person = _people.First(x => x.Id == id);var person = _people.First(x => x.Id == id);return new HttpResponseMessage<Person>(return new HttpResponseMessage<Person>(person,person,HttpStatusCode.OKHttpStatusCode.OK););}}catchcatch{{return newreturn newHttpResponseMessage<Person>(HttpStatusCode.NotFound);HttpResponseMessage<Person>(HttpStatusCode.NotFound);}}}}ExampleFind a person and return it,but what happens if we don’tfind a match?
  • Manipulating HTTP ResponsesA successful API call returns an HTTP OK and the JSON data
  • Manipulating HTTP ResponsesAn unsuccessful API call returns an HTTP 404 (and no JSON)
  • Making an API Updatable
  • Posting Data to a Web APIpublic HttpResponseMessage Post(Person person)public HttpResponseMessage Post(Person person){{person.Id = _people.Count + 1;person.Id = _people.Count + 1;if (_people.Any(x => x.Id == person.Id))if (_people.Any(x => x.Id == person.Id))return newreturn newHttpResponseMessage(HttpStatusCode.BadRequest);HttpResponseMessage(HttpStatusCode.BadRequest);trytry{{_people.Add(person);_people.Add(person);}}catchcatch{{return newreturn newHttpResponseMessage(HttpStatusCode.BadRequest);HttpResponseMessage(HttpStatusCode.BadRequest);}}return new HttpResponseMessage(HttpStatusCode.OK);return new HttpResponseMessage(HttpStatusCode.OK);}}Use HTTP Post:Pass a Model
  • Posting Data to a Web API