Date post: | 30-Jun-2015 |
Category: |
Technology |
Upload: | radenko-zec |
View: | 104 times |
Download: | 1 times |
Razvoj REST API-ja za Windows Azure
koristeći ASP.NET Web APIRadenko 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 protokol ni standard
Š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
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
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
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
Rast Web API-ja
Kako implementirati Web API
• Nasljediti klasu ApiController
• Implementirati akcije
– akcije se mapiraju na HTTP metode
– stavite prefix ispred metoda za željeni HTTP method
(PostCustomer)
DEMO
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
Validacija
• Validacija se vrši na podacima prilikom svakog
request-a
• greške prilikom validacije se snimaju u
ModelState
• provjerite ModelState.IsValid
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
HTTP Dispatcher
Invoke Action
Action filters
Model Bind
Select action Exception filters
Route to controller Formatting
Request Response
Authorization filters
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
IApiExplorer
public ActionResult Index()
{
var apiExplorer =GlobalConfiguration.Configuration.Services.GetApiExplorer();
return View(apiExplorer);
}
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
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 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:
Microsoft and
Open Sourcegateway for deeper
exploration of
open source
engagementshttp://www.microsoft.com
/openness
Port25blogs from the
platform
community and
the OSS Lab
teams http://Port25.technet.com
Codeplexresources for
developers and
consumers of
open source
projectshttp://www.codeplex.com
Interoperability
Bridgestechnical collaborative
works http://www.interoperabilit
ybridges.com
Open Upcross-Industry
Interoperability
and Standards
activitieshttp://www.microsoft.com
/interop/openup
Shared Sourceportal for
programmaticall
y sharing codehttp://www.microsoft.com
/sharedsource
ODataopen source starter kit
for Internet
publishing of
Government
datasets using
the Open Datahttp://ogdisdk.cloudapp.ne
t
Open Specprotocols, file formats,
standards,
technical
specificationshttp://www.microsoft.com
/openspecification
s
BizSparkProgram for Start-Up
companies from
both
commercial and
open source
backgroundshttp://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