0
Building Service for Any ClientsLohith G NTelerik
ABOUT ME• Developer Evangelist, Telerik India• Microsoft MVP• @kashyapa• Lohith.Nagaraj@telerik.com• www.Kashyapas.com• ww...
Telerik at a Glance• Established in 2002• Telerik is now a leading vendor of productivity tools & solutions• 11 global off...
End to End ProviderSolutions for all aspects of Software DevelopmentAutomated Functional & PerformanceUI TestingUnit Testi...
Telerik Product PortfolioPlanPlan BuildBuild TestTest DeliverDeliverAGILE PROJECTAGILE PROJECTMANAGEMENTMANAGEMENTDEVELOPE...
Agenda• How does ASP.NET Web API fit in?• Introduction to Web API• Consuming Web API from jQuery• Consuming Web API from W...
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...
Read-only Controller Actions toreturn data// GET /api/person// GET /api/personpublic IEnumerable<Person> Get()public IEnum...
Routing a Web API UsingGlobal.asax.cspublic static voidpublic static voidRegisterRoutes(RouteCollectionRegisterRoutes(Rout...
Manipulating HTTP Responses// GET /api/person/5// GET /api/person/5public HttpResponseMessage<Person> Get(int id)public Ht...
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){{per...
Posting Data to a Web API
GIDS13 - Building Service for Any Clients
Upcoming SlideShare
Loading in...5
×

GIDS13 - Building Service for Any Clients

464

Published on

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.

Published in: Technology
1 Comment
0 Likes
Statistics
Notes
  • 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....
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total Views
464
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
5
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide
  • Michael
  • Telerik truly is an end to end provider of tools for developers
  • Transcript of "GIDS13 - Building Service for Any Clients"

    1. 1. Building Service for Any ClientsLohith G NTelerik
    2. 2. ABOUT ME• Developer Evangelist, Telerik India• Microsoft MVP• @kashyapa• Lohith.Nagaraj@telerik.com• www.Kashyapas.com• www.Telerikhelper.net
    3. 3. 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”
    4. 4. 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
    5. 5. 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
    6. 6. Agenda• How does ASP.NET Web API fit in?• Introduction to Web API• Consuming Web API from jQuery• Consuming Web API from Windows 8
    7. 7. Web API is part of ASP.NETASP.NET Core
    8. 8. WHERE CAN YOU GET WEBAPI
    9. 9. www.asp.net/web-api
    10. 10. Building a read only Web API
    11. 11. 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
    12. 12. 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
    13. 13. 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
    14. 14. 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?
    15. 15. Manipulating HTTP ResponsesA successful API call returns an HTTP OK and the JSON data
    16. 16. Manipulating HTTP ResponsesAn unsuccessful API call returns an HTTP 404 (and no JSON)
    17. 17. Making an API Updatable
    18. 18. 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
    19. 19. Posting Data to a Web API
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×