Download - Conhecendo os recursos do ASP.NET Web API
![Page 1: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/1.jpg)
CONHECENDO OS RECURSOS DO ASP.NET WEB
APIIvan PaulovichMVP ASP.NET / IIS
Marcus CoelhoMCT
![Page 3: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/3.jpg)
Marcus Coelho
![Page 4: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/4.jpg)
Conhecendo o ASP.NET Web API
• Serviços HTTP• Acessível por um conjunto de clientes• Ideal para aplicações RESTful• Separação de responsabilidades
![Page 5: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/5.jpg)
DEMO VAPT-VUPT
![Page 6: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/6.jpg)
Criando uma WebAPI com suporte a CRUD
• Web API Template• jQuery
![Page 7: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/7.jpg)
Roteamento
Action Http Method Url
Get a list of all contacts GET /api/contacts
Get a contacts by ID GET /api/contacts/id
Create a new contact POST /api/contacts
Update a contact PUT /api/contacts/id
Delete a contact DELETE /api/contacts/id
![Page 8: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/8.jpg)
Consultas e Paginação
Parâmetro Descrição Exemplo
$filter Seleciona os elementos que atendem a restrição
http://localhost:9000/api/contacts?$filter=substringof(Name, 'Ed') eq true
$orderby Ordena os resultados por uma propriedade específica
http://localhost:9000/api/contacts?$orderby=Name
$skip Pula os primeiros n elementos. http://localhost:9000/api/contacts?$skip=2
$top Retorna os primeiros n elementos na lista. Se combinado com $orderby, a lista é ordenada primeiro, e os primeiros n elementos da lista ordenada são retornados.
http://localhost:9000/api/contacts? $top=3&$orderby=Name
![Page 9: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/9.jpg)
Read e Create
![Page 10: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/10.jpg)
Update e Delete
![Page 11: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/11.jpg)
Tratamento de exceções
• HttpResponseException• Exception Filters• ExceptionFilterAttribute
![Page 12: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/12.jpg)
DEMO
![Page 13: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/13.jpg)
Self-Host a Web API
• HTTP URL Namespace Reservationnetsh http add urlacl url=http://+:8080/ user=SG1\Ivan
• Simples• Independente– Console Application
![Page 14: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/14.jpg)
Model
![Page 15: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/15.jpg)
ApiController
![Page 16: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/16.jpg)
Servidor
![Page 17: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/17.jpg)
DEMO
![Page 18: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/18.jpg)
Outras funcionalidades
• Autorização• Validação customizada
![Page 19: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/19.jpg)
Links Úteis
• http://www.asp.net/web-api
• http://www.asp.net/vnext/overview/downloads
![Page 20: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/20.jpg)
Palestras Relacionadas
• 15/Maio 21h - CSharp-B03Entity Framework 5 - A ferramenta de ORM que todo desenvolvedor deve conhecer
• 16/Maio 19h - Web-A01Criando aplicações Web com ASP.NET MVC 4
![Page 21: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/21.jpg)
PERGUNTAS?
![Page 22: Conhecendo os recursos do ASP.NET Web API](https://reader037.vdocuments.pub/reader037/viewer/2022103114/5560b4ced8b42afe3b8b4907/html5/thumbnails/22.jpg)