Embed presentation
Downloaded 369 times




![Level 0: The swamp of POX
• Use RPC (Remote Procedure Invocation)
• POST /appointmentService HTTP/1.1 [various
other headers]
<openSlotRequest date = "2010-01-04" doctor =
"mjones"/>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-5-320.jpg)
![• The server return an open slot list as
HTTP/1.1 200 OK [various headers]
<openSlotList>
<slot start = "1400" end = "1450">
<doctor id = “mjones”/>
</slot>
<slot start = "1600" end = "1650">
<doctor id = “mjones”/>
</slot>
</openSlotList>
• We choose the the first item and send it to server:
POST /appointmentService HTTP/1.1 [various other headers]
<appointmentRequest>
<slot doctor = "mjones" start = "1400" end =
"1450"/>
<patient id = "jsmith"/>
</appointmentRequest>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-6-320.jpg)
![• The server accept this request and register
name of patient
HTTP/1.1 200 OK [various headers]
<appointment>
<slot doctor = "mjones" start = "1400" end = "1450"/>
<patient id = "jsmith"/>
</appointment>
• If some thing wrong, the result should be
HTTP/1.1 200 OK [various headers]
<appointmentRequestFailure>
<slot doctor = "mjones" start = "1400" end = "1450"/>
<patient id = "jsmith"/>
<reason>Slot not available</reason>
</appointmentRequestFailure>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-7-320.jpg)

![• POST /doctors/mjones HTTP/1.1 [various
other headers]
<openSlotRequest date = "2010-01-04"/>
• HTTP/1.1 200 OK [various headers]
<openSlotList>
<slot id = "1234" doctor = "mjones" start = "1400"
end = "1450"/>
<slot id = "5678" doctor = "mjones" start = "1600"
end = "1650"/>
</openSlotList>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-9-320.jpg)
![• POST /slots/1234 HTTP/1.1 [various other
headers]
<appointmentRequest>
<patient id = "jsmith"/>
</appointmentRequest>
• HTTP/1.1 200 OK [various headers]
<appointment>
<slot id = "1234" doctor = "mjones" start = "1400"
end = "1450"/>
<patient id = "jsmith"/>
</appointment>
• The link at the moment should be like this
– http://royalhope.nhs.uk/slots/1234/appointment](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-10-320.jpg)

![• Use GET
/doctors/mjones/slots?date=20100104&status=open
HTTP/1.1 Host: royalhope.nhs.uk
• HTTP/1.1 200 OK [various headers]
<openSlotList>
<slot id = "1234" doctor = "mjones" start = "1400"
end = "1450"/>
<slot id = "5678" doctor = "mjones" start = "1600"
end = "1650"/>
</openSlotList>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-12-320.jpg)
![• POST /slots/1234 HTTP/1.1 [various other
headers]
<appointmentRequest>
<patient id = "jsmith"/>
</appointmentRequest>
• HTTP/1.1 201 Created Location:
slots/1234/appointment [various headers]
<appointment>
<slot id = "1234" doctor = "mjones" start =
"1400" end = "1450"/>
<patient id = "jsmith"/>
</appointment>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-13-320.jpg)
![• If something wrong when we use POST to
server, the result should be
HTTP/1.1 409 Conflict [various headers]
<openSlotList>
<slot id = "5678" doctor = "mjones" start =
"1600" end = "1650"/>
</openSlotList>
• Benefits:
– Caching on GET request (natural capability with
HTTP protocol)](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-14-320.jpg)

![• GET
/doctors/mjones/slots?date=20100104&status=o
pen HTTP/1.1 Host: royalhope.nhs.uk
• HTTP/1.1 200 OK [various headers]
<openSlotList>
<slot id = "1234" doctor = "mjones" start = "1400"
end = "1450">
<link rel = "/linkrels/slot/book" uri =
"/slots/1234"/>
</slot>
<slot id = "5678" doctor = "mjones" start = "1600"
end = "1650">
<link rel = "/linkrels/slot/book" uri =
"/slots/5678"/>
</slot>
</openSlotList>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-16-320.jpg)
![• POST /slots/1234 HTTP/1.1 [various other
headers]
<appointmentRequest>
<patient id = "jsmith"/>
</appointmentRequest>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-17-320.jpg)
![• HTTP/1.1 201 Created Location:
http://royalhope.nhs.uk/slots/1234/appointment [various headers]
<appointment>
<slot id = "1234" doctor = "mjones" start = "1400" end = "1450"/>
<patient id = "jsmith"/>
<link rel = "/linkrels/appointment/cancel" uri =
"/slots/1234/appointment"/>
<link rel = "/linkrels/appointment/addTest" uri =
"/slots/1234/appointment/tests"/>
<link rel = "self" uri = "/slots/1234/appointment"/>
<link rel = "/linkrels/appointment/changeTime" uri =
"/doctors/mjones/slots?date=20100104@status=open"/>
<link rel = "/linkrels/appointment/updateContactInfo" uri =
"/patients/jsmith/contactInfo"/>
<link rel = "/linkrels/help" uri = "/help/appointment"/>
</appointment>
• What’s benefit of those?](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-18-320.jpg)




![Web API service
public class SurveyAPIController : BaseApiController
{
// GET api/Survey
[Queryable]
public IQueryable<SurveyDTO> Get() {
return _surveyAppService.GetAllSurvey().AsQueryable();
}
// GET api/Survey/5
public SurveyDTO Get(int id) { … }
// POST api/Survey
public HttpResponseMessage Post(SurveyDTO value) { … }
// PUT api/Survey/5
public HttpResponseMessage Put(int id, SurveyDTO value) { … }
// DELETE api/Survey/5
public HttpResponseMessage Delete(int id) {… }
}](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-23-320.jpg)









This document provides an overview of ASP.NET Web API including: - A model of REST maturity with 4 levels from plain XML to hypermedia controls. - The purpose of Web APIs as RESTful HTTP services compared to SOAP. - Mapping from WCF to the Web API model using controllers, actions, and routing instead of endpoints. - Features like content negotiation, model binding, and dependency injection supported in the Web API stack.




![Level 0: The swamp of POX
• Use RPC (Remote Procedure Invocation)
• POST /appointmentService HTTP/1.1 [various
other headers]
<openSlotRequest date = "2010-01-04" doctor =
"mjones"/>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-5-320.jpg)
![• The server return an open slot list as
HTTP/1.1 200 OK [various headers]
<openSlotList>
<slot start = "1400" end = "1450">
<doctor id = “mjones”/>
</slot>
<slot start = "1600" end = "1650">
<doctor id = “mjones”/>
</slot>
</openSlotList>
• We choose the the first item and send it to server:
POST /appointmentService HTTP/1.1 [various other headers]
<appointmentRequest>
<slot doctor = "mjones" start = "1400" end =
"1450"/>
<patient id = "jsmith"/>
</appointmentRequest>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-6-320.jpg)
![• The server accept this request and register
name of patient
HTTP/1.1 200 OK [various headers]
<appointment>
<slot doctor = "mjones" start = "1400" end = "1450"/>
<patient id = "jsmith"/>
</appointment>
• If some thing wrong, the result should be
HTTP/1.1 200 OK [various headers]
<appointmentRequestFailure>
<slot doctor = "mjones" start = "1400" end = "1450"/>
<patient id = "jsmith"/>
<reason>Slot not available</reason>
</appointmentRequestFailure>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-7-320.jpg)

![• POST /doctors/mjones HTTP/1.1 [various
other headers]
<openSlotRequest date = "2010-01-04"/>
• HTTP/1.1 200 OK [various headers]
<openSlotList>
<slot id = "1234" doctor = "mjones" start = "1400"
end = "1450"/>
<slot id = "5678" doctor = "mjones" start = "1600"
end = "1650"/>
</openSlotList>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-9-320.jpg)
![• POST /slots/1234 HTTP/1.1 [various other
headers]
<appointmentRequest>
<patient id = "jsmith"/>
</appointmentRequest>
• HTTP/1.1 200 OK [various headers]
<appointment>
<slot id = "1234" doctor = "mjones" start = "1400"
end = "1450"/>
<patient id = "jsmith"/>
</appointment>
• The link at the moment should be like this
– http://royalhope.nhs.uk/slots/1234/appointment](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-10-320.jpg)

![• Use GET
/doctors/mjones/slots?date=20100104&status=open
HTTP/1.1 Host: royalhope.nhs.uk
• HTTP/1.1 200 OK [various headers]
<openSlotList>
<slot id = "1234" doctor = "mjones" start = "1400"
end = "1450"/>
<slot id = "5678" doctor = "mjones" start = "1600"
end = "1650"/>
</openSlotList>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-12-320.jpg)
![• POST /slots/1234 HTTP/1.1 [various other
headers]
<appointmentRequest>
<patient id = "jsmith"/>
</appointmentRequest>
• HTTP/1.1 201 Created Location:
slots/1234/appointment [various headers]
<appointment>
<slot id = "1234" doctor = "mjones" start =
"1400" end = "1450"/>
<patient id = "jsmith"/>
</appointment>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-13-320.jpg)
![• If something wrong when we use POST to
server, the result should be
HTTP/1.1 409 Conflict [various headers]
<openSlotList>
<slot id = "5678" doctor = "mjones" start =
"1600" end = "1650"/>
</openSlotList>
• Benefits:
– Caching on GET request (natural capability with
HTTP protocol)](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-14-320.jpg)

![• GET
/doctors/mjones/slots?date=20100104&status=o
pen HTTP/1.1 Host: royalhope.nhs.uk
• HTTP/1.1 200 OK [various headers]
<openSlotList>
<slot id = "1234" doctor = "mjones" start = "1400"
end = "1450">
<link rel = "/linkrels/slot/book" uri =
"/slots/1234"/>
</slot>
<slot id = "5678" doctor = "mjones" start = "1600"
end = "1650">
<link rel = "/linkrels/slot/book" uri =
"/slots/5678"/>
</slot>
</openSlotList>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-16-320.jpg)
![• POST /slots/1234 HTTP/1.1 [various other
headers]
<appointmentRequest>
<patient id = "jsmith"/>
</appointmentRequest>](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-17-320.jpg)
![• HTTP/1.1 201 Created Location:
http://royalhope.nhs.uk/slots/1234/appointment [various headers]
<appointment>
<slot id = "1234" doctor = "mjones" start = "1400" end = "1450"/>
<patient id = "jsmith"/>
<link rel = "/linkrels/appointment/cancel" uri =
"/slots/1234/appointment"/>
<link rel = "/linkrels/appointment/addTest" uri =
"/slots/1234/appointment/tests"/>
<link rel = "self" uri = "/slots/1234/appointment"/>
<link rel = "/linkrels/appointment/changeTime" uri =
"/doctors/mjones/slots?date=20100104@status=open"/>
<link rel = "/linkrels/appointment/updateContactInfo" uri =
"/patients/jsmith/contactInfo"/>
<link rel = "/linkrels/help" uri = "/help/appointment"/>
</appointment>
• What’s benefit of those?](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-18-320.jpg)




![Web API service
public class SurveyAPIController : BaseApiController
{
// GET api/Survey
[Queryable]
public IQueryable<SurveyDTO> Get() {
return _surveyAppService.GetAllSurvey().AsQueryable();
}
// GET api/Survey/5
public SurveyDTO Get(int id) { … }
// POST api/Survey
public HttpResponseMessage Post(SurveyDTO value) { … }
// PUT api/Survey/5
public HttpResponseMessage Put(int id, SurveyDTO value) { … }
// DELETE api/Survey/5
public HttpResponseMessage Delete(int id) {… }
}](https://image.slidesharecdn.com/webapisclides-120806144829-phpapp01/85/ASP-NET-WEB-API-23-320.jpg)







