Your SlideShare is downloading. ×
0
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
GIDS13 - Building Service for Any Clients
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

GIDS13 - Building Service for Any Clients

461

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.

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
461
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
5
Comments
1
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Michael
  • Telerik truly is an end to end provider of tools for developers
  • Transcript

    • 1. Building Service for Any ClientsLohith G NTelerik
    • 2. ABOUT ME• Developer Evangelist, Telerik India• Microsoft MVP• @kashyapa• Lohith.Nagaraj@telerik.com• www.Kashyapas.com• www.Telerikhelper.net
    • 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. 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. 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. 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. Web API is part of ASP.NETASP.NET Core
    • 8. WHERE CAN YOU GET WEBAPI
    • 9. www.asp.net/web-api
    • 10. Building a read only Web API
    • 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. 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. 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. 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. Manipulating HTTP ResponsesA successful API call returns an HTTP OK and the JSON data
    • 16. Manipulating HTTP ResponsesAn unsuccessful API call returns an HTTP 404 (and no JSON)
    • 17. Making an API Updatable
    • 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. Posting Data to a Web API

    ×