Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Razvoj REST API-ja za Windows Azure
koristeći ASP.NET Web API
Radenko Zec, Lanaco d.o.o
October 24rd, 2012
Cilj prezentacije
• napraviti “Real World” Web API koristeći
ASP.NET Web API
Šta je REST ?
• to je stil softverske arhitekture, za distribuirane
hypermedia sisteme kao što je „World Wide Web“
• nije ...
Šta je ASP.NET Web API ?
• Frejmvork koji omogućava lak razvoj HTTP
servisa kojima se može pristupati sa velikog
broja raz...
Da li je ASP.NET Web API =
RESTful service?
• ASP.NET Web API ne diktira stil arhitekture
• ali vi možete da razvijete RES...
Richardson-ov model zrelosti
REST-a
Zašto Web API ?
+
Skaliranje u oblaku
Koje metode ASP.NET Web API
podržava
Metod Akcija HTTPMetod Relativni URI
Get Vraća listu svih
kontakata
GET /api/contacts...
Rast Web API-ja
Kako implementirati Web API
• Nasljediti klasu ApiController
• Implementirati akcije
– akcije se mapiraju na HTTP metode
–...
DEMO
Action parameters
• prosti tipovi se dobijaju iz URI-ja
– route data, query parameters
http://api.mssinergija.net/kontakt?...
Validacija
• Validacija se vrši na podacima prilikom svakog
request-a
• greške prilikom validacije se snimaju u
ModelState...
Filteri
• Tipovi filtera :
– Action filters (pokreću se prije i nakon poziva akcije)
– Authorization filters (pokreću se p...
HTTP Dispatcher
Invoke Action
Action filters
Model Bind
Select action Exception filters
Route to controller Formatting
Req...
Opis Web API-ja
• koristi se IApiExplorer servis da bi se dobio
runtime opis Web API-ja
• korisno prilikom izrade help str...
IApiExplorer
public ActionResult Index()
{
var apiExplorer =
GlobalConfiguration.Configuration.Services.
GetApiExplorer();...
Hosting
• dva načina hostovanja
– ASP.NET Web Application (IIS)
– Self-host (npr. console application, Windows service,
Az...
DEMO
http://blog.developers.ba
@radenkozec
Hvala na pažnji.
Help us choose the best Sinergija lecturer! HTC and Microsoft will award you
– at the conference end, we’ll give one HTC W...
Microsoft and
Open Source
gateway for deeper
exploration of
open source
engagements
http://www.microsoft.com
/openness
Por...
Upcoming SlideShare
Loading in …5
×

Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API

348 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API

  1. 1. Razvoj REST API-ja za Windows Azure koristeći ASP.NET Web API Radenko Zec, Lanaco d.o.o October 24rd, 2012
  2. 2. Cilj prezentacije • napraviti “Real World” Web API koristeći ASP.NET Web API
  3. 3. Šta je REST ? • to je stil softverske arhitekture, za distribuirane hypermedia sisteme kao što je „World Wide Web“ • nije protokol ni standard
  4. 4. Šta je ASP.NET Web API ? • Frejmvork koji omogućava lak razvoj HTTP servisa kojima se može pristupati sa velikog broja različitih klijenata uključujući browsere i mobilne uređaje
  5. 5. Da li je ASP.NET Web API = RESTful service? • ASP.NET Web API ne diktira stil arhitekture • ali vi možete da razvijete RESTful service pomoću ASP.NET Web API- ja
  6. 6. Richardson-ov model zrelosti REST-a
  7. 7. Zašto Web API ? +
  8. 8. Skaliranje u oblaku
  9. 9. Koje metode ASP.NET Web API podržava Metod Akcija HTTPMetod Relativni URI Get Vraća listu svih kontakata GET /api/contacts Get Vraća kontakt na osnovu id-a GET /api/contacts/id Add Dodaje novi kontakt POST /api/contacts Update Mijenja selektovani kontakt PUT /api/contacts Delete Briše kontakt DELETE /api/contacts/id
  10. 10. Rast Web API-ja
  11. 11. Kako implementirati Web API • Nasljediti klasu ApiController • Implementirati akcije – akcije se mapiraju na HTTP metode – stavite prefix ispred metoda za željeni HTTP method (PostCustomer)
  12. 12. DEMO
  13. 13. Action parameters • prosti tipovi se dobijaju iz URI-ja – route data, query parameters http://api.mssinergija.net/kontakt?kod=nesto • kompleksni tipovi – request body – MediaTypeFormatters koriste se za deserijalizaciju Request Body-ja zavisno od content type-a – JSON i XML su podržani pod default-u
  14. 14. Validacija • Validacija se vrši na podacima prilikom svakog request-a • greške prilikom validacije se snimaju u ModelState • provjerite ModelState.IsValid
  15. 15. Filteri • Tipovi filtera : – Action filters (pokreću se prije i nakon poziva akcije) – Authorization filters (pokreću se prije model binding-a i služe za autorizaciju korisnika) – Exception filters (generišu odgovor u slučaju greške na centralizovan način) • Oni mogu biti konfigurisani globalno, po kontroleru i po akciji
  16. 16. HTTP Dispatcher Invoke Action Action filters Model Bind Select action Exception filters Route to controller Formatting Request Response Authorization filters
  17. 17. Opis Web API-ja • koristi se IApiExplorer servis da bi se dobio runtime opis Web API-ja • korisno prilikom izrade help stranica, test klijenata, alata i sl. • http://nuget.org/packages/Microsoft.AspNet.Web Api.HelpPage
  18. 18. IApiExplorer public ActionResult Index() { var apiExplorer = GlobalConfiguration.Configuration.Services. GetApiExplorer(); return View(apiExplorer); }
  19. 19. Hosting • dva načina hostovanja – ASP.NET Web Application (IIS) – Self-host (npr. console application, Windows service, Azure Worker Role, itd.) • hostovanje u memoriji je korisno za integration testiranje servisa
  20. 20. DEMO
  21. 21. http://blog.developers.ba @radenkozec
  22. 22. Hvala na pažnji.
  23. 23. Help us choose the best Sinergija lecturer! HTC and Microsoft will award you – at the conference end, we’ll give one HTC Windows Phone 8X to someone from the audience – randomly. Go to www.mssinergija.net, log in and cast your votes! You can rate only lectures that you were present at, just once. More lectures you rate, more chances you have. Please use computers at the front of this room, or rate lecture from your phone or home computer, at Sinergija portal. This prize contest will end at Thursday, October 24th at 21:00. Winner will be announced at the official Sinergija web portal, www.mssinergija.net Please rate this lecture and WIN Windows Phone 8X by HTC! Powered by:
  24. 24. Microsoft and Open Source gateway for deeper exploration of open source engagements http://www.microsoft.com /openness Port25 blogs from the platform community and the OSS Lab teams http://Port25.technet.com Codeplex resources for developers and consumers of open source projects http://www.codeplex.com Interoperability Bridges technical collaborative works http://www.interoperabilit ybridges.com Open Up cross-Industry Interoperability and Standards activities http://www.microsoft.com /interop/openup Shared Source portal for programmaticall y sharing code http://www.microsoft.com /sharedsource OData open source starter kit for Internet publishing of Government datasets using the Open Data http://ogdisdk.cloudapp.ne t Open Spec protocols, file formats, standards, technical specifications http://www.microsoft.com /openspecification s BizSpark Program for Start-Up companies from both commercial and open source backgrounds http://www.microsoft.com /bizspark Openness and Interoperability @Microsoft How can I receive up-to-date Openness announcements from Microsoft? In addition to the websites above, you can receive regular updates to Microsoft’s openness, interoperability and standards efforts via the following channels: • http://blogs.technet.com/b/openness/ • http://blogs.msdn.com/b/interoperability/ • http://twitter.com/OpenAtMicrosoft • http://port25.technet.com • http://channel9.msdn.com/Blogs/Interoperability

×