SlideShare a Scribd company logo
1 of 20
Building Service for Any Clients
Lohith G N
Telerik
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 Than
Expected”Expected”
End to End Provider
Solutions for all aspects of Software Development
Automated Functional & Performance
UI Testing
Unit Testing
Load/Stress Testing
Exploratry Testing
Testing
Requirements Gathering
Project Management
Defect Management
Team and Customer Collaboration
Planning
Multi-platform UI tools
Code quality and performance tools
Data access and reporting tools
Construction
Telerik Product Portfolio
PlanPlan BuildBuild TestTest DeliverDeliver
AGILE PROJECTAGILE PROJECT
MANAGEMENTMANAGEMENT
DEVELOPER TOOLSDEVELOPER TOOLS QUALITY ASSURANCEQUALITY ASSURANCE
TOOLSTOOLS
WEB PRESENCEWEB PRESENCE
PLATFORMPLATFORM
Windows Phone*
Sitefinity
OpenAccess ORM
Silverlight
WinForms
Reporting
JustCode
WPF Controls
ASP.NET MVC
JustMock
ASP.NET AJAX*
JustDecompile
TeamPulse
Windows 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.NET
ASP.NET Core
WHERE CAN YOU GET WEB
API
www.asp.net/web-api
Building a read only Web API
Sample Read-only Model and
Controller
public 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 Model
public 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 = "Chuck
Norris" },Norris" },
new Person { Id = 2, Name = "Davidnew Person { Id = 2, Name = "David
Carradine" },Carradine" },
new Person { Id = 3, Name = "Brucenew Person { Id = 3, Name = "Bruce
Lee" }Lee" }
});});
}}
}}
Step 2:
Make an API Controller
Read-only Controller Actions to
return data
// GET /api/person// GET /api/person
public IEnumerable<Person> Get()public IEnumerable<Person> Get()
{{
return _people;return _people;
}}
Step 3:
Return everything
// GET /api/person/5// GET /api/person/5
public 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 Using
Global.asax.cs
public static voidpublic static void
RegisterRoutes(RouteCollectionRegisterRoutes(RouteCollection
routes)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/5
public 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 new
HttpResponseMessage<Person>(HttpStatusCode.NotFound);HttpResponseMessage<Person>(HttpStatusCode.NotFound);
}}
}}
Example
Find a person and return it,
but what happens if we don’t
find a match?
Manipulating HTTP Responses
A successful API call returns an HTTP OK and the JSON data
Manipulating HTTP Responses
An unsuccessful API call returns an HTTP 404 (and no JSON)
Making an API Updatable
Posting Data to a Web API
public 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 new
HttpResponseMessage(HttpStatusCode.BadRequest);HttpResponseMessage(HttpStatusCode.BadRequest);
trytry
{{
_people.Add(person);_people.Add(person);
}}
catchcatch
{{
return newreturn new
HttpResponseMessage(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
GIDS13 - Building Service for Any Clients

More Related Content

What's hot

Spca2014 office365 ap is full hackett obrien
Spca2014 office365 ap is full hackett obrienSpca2014 office365 ap is full hackett obrien
Spca2014 office365 ap is full hackett obrien
NCCOMMS
 

What's hot (20)

apidays LIVE Paris 2021 - Building an analytics API by David Wobrock, Botify
apidays LIVE Paris 2021 - Building an analytics API by David Wobrock, Botifyapidays LIVE Paris 2021 - Building an analytics API by David Wobrock, Botify
apidays LIVE Paris 2021 - Building an analytics API by David Wobrock, Botify
 
AutoRABIT solution for Salesforce DX / Agile dev on SFDC & Force.com
AutoRABIT solution for Salesforce DX / Agile dev on SFDC & Force.com AutoRABIT solution for Salesforce DX / Agile dev on SFDC & Force.com
AutoRABIT solution for Salesforce DX / Agile dev on SFDC & Force.com
 
apidays LIVE London 2021 - Rethink API Troubleshooting to Deliver Value by Sa...
apidays LIVE London 2021 - Rethink API Troubleshooting to Deliver Value by Sa...apidays LIVE London 2021 - Rethink API Troubleshooting to Deliver Value by Sa...
apidays LIVE London 2021 - Rethink API Troubleshooting to Deliver Value by Sa...
 
apidays LIVE Paris 2021 - Using OpenAPI to configure your API Gateway by Ole ...
apidays LIVE Paris 2021 - Using OpenAPI to configure your API Gateway by Ole ...apidays LIVE Paris 2021 - Using OpenAPI to configure your API Gateway by Ole ...
apidays LIVE Paris 2021 - Using OpenAPI to configure your API Gateway by Ole ...
 
Scribe Online CDK & Connector Development
Scribe Online CDK & Connector DevelopmentScribe Online CDK & Connector Development
Scribe Online CDK & Connector Development
 
Testing Mobile Applications With Telerik Platform
Testing Mobile Applications With Telerik PlatformTesting Mobile Applications With Telerik Platform
Testing Mobile Applications With Telerik Platform
 
Can virtualization transform your API lifecycle?
Can virtualization transform your API lifecycle?Can virtualization transform your API lifecycle?
Can virtualization transform your API lifecycle?
 
RightScale Webinar: Provide a Self-Service Portal for vSphere, AWS and Other ...
RightScale Webinar: Provide a Self-Service Portal for vSphere, AWS and Other ...RightScale Webinar: Provide a Self-Service Portal for vSphere, AWS and Other ...
RightScale Webinar: Provide a Self-Service Portal for vSphere, AWS and Other ...
 
Build sfdx plugin in 15 minutes
Build sfdx plugin in 15 minutesBuild sfdx plugin in 15 minutes
Build sfdx plugin in 15 minutes
 
Service api design validation & collaboration
Service api design validation & collaborationService api design validation & collaboration
Service api design validation & collaboration
 
Spca2014 office365 ap is full hackett obrien
Spca2014 office365 ap is full hackett obrienSpca2014 office365 ap is full hackett obrien
Spca2014 office365 ap is full hackett obrien
 
What is DevOps?
What is DevOps?What is DevOps?
What is DevOps?
 
Life After Microservices – Shifting the Boundaries
Life After Microservices – Shifting the BoundariesLife After Microservices – Shifting the Boundaries
Life After Microservices – Shifting the Boundaries
 
BizTalk 2010 with Appfabric Hosting in the Cloud: WCF Services vs BT2010
BizTalk 2010 with Appfabric Hosting in the Cloud: WCF Services vs BT2010BizTalk 2010 with Appfabric Hosting in the Cloud: WCF Services vs BT2010
BizTalk 2010 with Appfabric Hosting in the Cloud: WCF Services vs BT2010
 
Existek Company Profile
Existek Company ProfileExistek Company Profile
Existek Company Profile
 
Summit 2014 Keynote
Summit 2014 KeynoteSummit 2014 Keynote
Summit 2014 Keynote
 
apidays LIVE London 2021 - Federating the Content Layer by Jamie Barton, Grap...
apidays LIVE London 2021 - Federating the Content Layer by Jamie Barton, Grap...apidays LIVE London 2021 - Federating the Content Layer by Jamie Barton, Grap...
apidays LIVE London 2021 - Federating the Content Layer by Jamie Barton, Grap...
 
[API World 2021 ] - Understanding Cloud Native Deployment
[API World 2021 ] - Understanding Cloud Native Deployment[API World 2021 ] - Understanding Cloud Native Deployment
[API World 2021 ] - Understanding Cloud Native Deployment
 
apidays LIVE Paris - GraphQL: the AppSec perspective by Vladimir de Turckheim
apidays LIVE Paris - GraphQL: the AppSec perspective by Vladimir de Turckheimapidays LIVE Paris - GraphQL: the AppSec perspective by Vladimir de Turckheim
apidays LIVE Paris - GraphQL: the AppSec perspective by Vladimir de Turckheim
 
Shift Remote: DevOps: Devops with Azure Devops and Github - Juarez Junior (Mi...
Shift Remote: DevOps: Devops with Azure Devops and Github - Juarez Junior (Mi...Shift Remote: DevOps: Devops with Azure Devops and Github - Juarez Junior (Mi...
Shift Remote: DevOps: Devops with Azure Devops and Github - Juarez Junior (Mi...
 

Viewers also liked

от Rookee
от Rookeeот Rookee
от Rookee
Anna
 
Golopolosov rotapost
Golopolosov   rotapostGolopolosov   rotapost
Golopolosov rotapost
Anna
 

Viewers also liked (6)

Magento online marketing
Magento online marketingMagento online marketing
Magento online marketing
 
от Rookee
от Rookeeот Rookee
от Rookee
 
Golopolosov rotapost
Golopolosov   rotapostGolopolosov   rotapost
Golopolosov rotapost
 
Shopper Typologies and Segmentation 2012
Shopper Typologies and Segmentation 2012Shopper Typologies and Segmentation 2012
Shopper Typologies and Segmentation 2012
 
14 Encontro dos Viajantes - Chile de Norte a Sul
14 Encontro dos Viajantes - Chile de Norte a Sul14 Encontro dos Viajantes - Chile de Norte a Sul
14 Encontro dos Viajantes - Chile de Norte a Sul
 
Key Characteristics of Strong Vocational Systems
Key Characteristics of Strong Vocational SystemsKey Characteristics of Strong Vocational Systems
Key Characteristics of Strong Vocational Systems
 

Similar to GIDS13 - Building Service for Any Clients

How Netflix Is Solving Authorization Across Their Cloud
How Netflix Is Solving Authorization Across Their CloudHow Netflix Is Solving Authorization Across Their Cloud
How Netflix Is Solving Authorization Across Their Cloud
Torin Sandall
 

Similar to GIDS13 - Building Service for Any Clients (20)

Building Your First App with MongoDB Stitch
Building Your First App with MongoDB StitchBuilding Your First App with MongoDB Stitch
Building Your First App with MongoDB Stitch
 
Google App Engine Developer - Day2
Google App Engine Developer - Day2Google App Engine Developer - Day2
Google App Engine Developer - Day2
 
Iac d.damyanov 4.pptx
Iac d.damyanov 4.pptxIac d.damyanov 4.pptx
Iac d.damyanov 4.pptx
 
Build an AI/ML-driven image archive processing workflow: Image archive, analy...
Build an AI/ML-driven image archive processing workflow: Image archive, analy...Build an AI/ML-driven image archive processing workflow: Image archive, analy...
Build an AI/ML-driven image archive processing workflow: Image archive, analy...
 
Getting Started with API Management – Why It's Needed On-prem and in the Cloud
Getting Started with API Management – Why It's Needed On-prem and in the CloudGetting Started with API Management – Why It's Needed On-prem and in the Cloud
Getting Started with API Management – Why It's Needed On-prem and in the Cloud
 
Made for Mobile - Let Office 365 Power Your Mobile Apps
Made for Mobile - Let Office 365 Power Your Mobile AppsMade for Mobile - Let Office 365 Power Your Mobile Apps
Made for Mobile - Let Office 365 Power Your Mobile Apps
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
 
Cloudbase.io MoSync Reload Course
Cloudbase.io MoSync Reload CourseCloudbase.io MoSync Reload Course
Cloudbase.io MoSync Reload Course
 
Tutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB StitchTutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB Stitch
 
ATAGTR2017 HikeRunner: Load Test Framework
ATAGTR2017 HikeRunner: Load Test FrameworkATAGTR2017 HikeRunner: Load Test Framework
ATAGTR2017 HikeRunner: Load Test Framework
 
How Netflix Is Solving Authorization Across Their Cloud
How Netflix Is Solving Authorization Across Their CloudHow Netflix Is Solving Authorization Across Their Cloud
How Netflix Is Solving Authorization Across Their Cloud
 
Cloud Native Serverless Java — Orkhan Gasimov
Cloud Native Serverless Java — Orkhan GasimovCloud Native Serverless Java — Orkhan Gasimov
Cloud Native Serverless Java — Orkhan Gasimov
 
Clean Architecture @ Taxibeat
Clean Architecture @ TaxibeatClean Architecture @ Taxibeat
Clean Architecture @ Taxibeat
 
Developing Apps with Azure AD
Developing Apps with Azure ADDeveloping Apps with Azure AD
Developing Apps with Azure AD
 
Centralizing users’ authentication at Active Directory level 
Centralizing users’ authentication at Active Directory level Centralizing users’ authentication at Active Directory level 
Centralizing users’ authentication at Active Directory level 
 
apidays LIVE LONDON - Exploring an API with Blocks by Larry Kluger
apidays LIVE LONDON - Exploring an API with Blocks by Larry Klugerapidays LIVE LONDON - Exploring an API with Blocks by Larry Kluger
apidays LIVE LONDON - Exploring an API with Blocks by Larry Kluger
 
Android Accessibility - The missing manual
Android Accessibility - The missing manualAndroid Accessibility - The missing manual
Android Accessibility - The missing manual
 
Practicing Red, Green, Refactor!
Practicing Red, Green, Refactor!Practicing Red, Green, Refactor!
Practicing Red, Green, Refactor!
 
apidays LIVE Paris - Exploring an API with Blocks by Larry Kluger
apidays LIVE Paris - Exploring an API with Blocks by Larry Klugerapidays LIVE Paris - Exploring an API with Blocks by Larry Kluger
apidays LIVE Paris - Exploring an API with Blocks by Larry Kluger
 
Building a Better BaaS
Building a Better BaaSBuilding a Better BaaS
Building a Better BaaS
 

More from Lohith Goudagere Nagaraj

More from Lohith Goudagere Nagaraj (20)

Porting Hybrid Apps to Native Apps
Porting Hybrid Apps to Native AppsPorting Hybrid Apps to Native Apps
Porting Hybrid Apps to Native Apps
 
Hybrid Mobile App Development With Cordova
Hybrid Mobile App Development With CordovaHybrid Mobile App Development With Cordova
Hybrid Mobile App Development With Cordova
 
Building Web Apps & APIs With Node JS
Building Web Apps & APIs With Node JSBuilding Web Apps & APIs With Node JS
Building Web Apps & APIs With Node JS
 
Even Quicker Development with Xamarin Forms Using Telerik UI for Xamarin
Even Quicker Development with Xamarin Forms Using Telerik UI for XamarinEven Quicker Development with Xamarin Forms Using Telerik UI for Xamarin
Even Quicker Development with Xamarin Forms Using Telerik UI for Xamarin
 
You Know Angular 2, You Know Native Mobile App Development
You Know Angular 2, You Know Native Mobile App DevelopmentYou Know Angular 2, You Know Native Mobile App Development
You Know Angular 2, You Know Native Mobile App Development
 
Connecting your .Net Applications to NoSQL Databases - MongoDB & Cassandra
Connecting your .Net Applications to NoSQL Databases - MongoDB & CassandraConnecting your .Net Applications to NoSQL Databases - MongoDB & Cassandra
Connecting your .Net Applications to NoSQL Databases - MongoDB & Cassandra
 
Angular JS 2.0 & React with Kendo UI
Angular JS 2.0 & React with Kendo UIAngular JS 2.0 & React with Kendo UI
Angular JS 2.0 & React with Kendo UI
 
Kendo UI Wrappers in ASP.NET Core
Kendo UI Wrappers in ASP.NET CoreKendo UI Wrappers in ASP.NET Core
Kendo UI Wrappers in ASP.NET Core
 
Seamless Access to Data from BI Tools using DataDirect Cloud
Seamless Access to Data from BI Tools using DataDirect CloudSeamless Access to Data from BI Tools using DataDirect Cloud
Seamless Access to Data from BI Tools using DataDirect Cloud
 
The Bleeding Edge - Whats New in Angular 2
The Bleeding Edge - Whats New in Angular 2The Bleeding Edge - Whats New in Angular 2
The Bleeding Edge - Whats New in Angular 2
 
Introduction to UWP - Universal Windows Platform Application Development
Introduction to UWP - Universal Windows Platform Application DevelopmentIntroduction to UWP - Universal Windows Platform Application Development
Introduction to UWP - Universal Windows Platform Application Development
 
Cross Platform Web Applications Using ASP.NET Core 1.0
Cross Platform Web Applications Using ASP.NET Core 1.0Cross Platform Web Applications Using ASP.NET Core 1.0
Cross Platform Web Applications Using ASP.NET Core 1.0
 
Build Leaner, Faster Web Applications with ASP.NET
Build Leaner, Faster Web Applications with  ASP.NETBuild Leaner, Faster Web Applications with  ASP.NET
Build Leaner, Faster Web Applications with ASP.NET
 
JavaScript Task Runners - Gulp & Grunt
JavaScript Task Runners - Gulp & GruntJavaScript Task Runners - Gulp & Grunt
JavaScript Task Runners - Gulp & Grunt
 
Visual Studio 2015 - Whats New ?
Visual Studio 2015 - Whats New ?Visual Studio 2015 - Whats New ?
Visual Studio 2015 - Whats New ?
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Online Spreadsheet for your Web Applications using Kendo UI
Online Spreadsheet for your Web Applications using Kendo UIOnline Spreadsheet for your Web Applications using Kendo UI
Online Spreadsheet for your Web Applications using Kendo UI
 
NativeScript + Push Notifications
NativeScript + Push NotificationsNativeScript + Push Notifications
NativeScript + Push Notifications
 
10 Useful New Features of ECMA Script 6
10 Useful New Features of ECMA Script 610 Useful New Features of ECMA Script 6
10 Useful New Features of ECMA Script 6
 
New Enterprisre Capabilities in Telerik Platform
New Enterprisre Capabilities in Telerik PlatformNew Enterprisre Capabilities in Telerik Platform
New Enterprisre Capabilities in Telerik Platform
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

GIDS13 - Building Service for Any Clients

  • 1. Building Service for Any Clients Lohith G N Telerik
  • 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 Than Expected”Expected”
  • 4. End to End Provider Solutions for all aspects of Software Development Automated Functional & Performance UI Testing Unit Testing Load/Stress Testing Exploratry Testing Testing Requirements Gathering Project Management Defect Management Team and Customer Collaboration Planning Multi-platform UI tools Code quality and performance tools Data access and reporting tools Construction
  • 5. Telerik Product Portfolio PlanPlan BuildBuild TestTest DeliverDeliver AGILE PROJECTAGILE PROJECT MANAGEMENTMANAGEMENT DEVELOPER TOOLSDEVELOPER TOOLS QUALITY ASSURANCEQUALITY ASSURANCE TOOLSTOOLS WEB PRESENCEWEB PRESENCE PLATFORMPLATFORM Windows Phone* Sitefinity OpenAccess ORM Silverlight WinForms Reporting JustCode WPF Controls ASP.NET MVC JustMock ASP.NET AJAX* JustDecompile TeamPulse Windows 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.NET ASP.NET Core
  • 8. WHERE CAN YOU GET WEB API
  • 10. Building a read only Web API
  • 11. Sample Read-only Model and Controller public 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 Model public 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 = "Chuck Norris" },Norris" }, new Person { Id = 2, Name = "Davidnew Person { Id = 2, Name = "David Carradine" },Carradine" }, new Person { Id = 3, Name = "Brucenew Person { Id = 3, Name = "Bruce Lee" }Lee" } });}); }} }} Step 2: Make an API Controller
  • 12. Read-only Controller Actions to return data // GET /api/person// GET /api/person public IEnumerable<Person> Get()public IEnumerable<Person> Get() {{ return _people;return _people; }} Step 3: Return everything // GET /api/person/5// GET /api/person/5 public 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 Using Global.asax.cs public static voidpublic static void RegisterRoutes(RouteCollectionRegisterRoutes(RouteCollection routes)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/5 public 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 new HttpResponseMessage<Person>(HttpStatusCode.NotFound);HttpResponseMessage<Person>(HttpStatusCode.NotFound); }} }} Example Find a person and return it, but what happens if we don’t find a match?
  • 15. Manipulating HTTP Responses A successful API call returns an HTTP OK and the JSON data
  • 16. Manipulating HTTP Responses An unsuccessful API call returns an HTTP 404 (and no JSON)
  • 17. Making an API Updatable
  • 18. Posting Data to a Web API public 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 new HttpResponseMessage(HttpStatusCode.BadRequest);HttpResponseMessage(HttpStatusCode.BadRequest); trytry {{ _people.Add(person);_people.Add(person); }} catchcatch {{ return newreturn new HttpResponseMessage(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

Editor's Notes

  1. Michael
  2. Telerik truly is an end to end provider of tools for developers