Web API with ASP.NET MVC by Software development company in india
ifourtechnolabindia
556 views
19 slides
Feb 23, 2017
Slide 1 of 19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
About This Presentation
ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.
Video :
https://youtu.be/qwLBeg1CPSo
Courtesy:
http:/...
ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.
Video :
https://youtu.be/qwLBeg1CPSo
Courtesy:
http://www.ifourtechnolab.com
Size: 572.86 KB
Language: en
Added: Feb 23, 2017
Slides: 19 pages
Slide Content
iFour Consultancy ASP.NET MVC Web API
ASP.NET Web API Why ASP.NET MVC Web API? ASP.NET Web API Features ASP.NET Web API Design ASP.NET MVC Web API Routing Table Error & Exception Handling Model Validation INDEX http://www.ifourtechnolab.com/ C# Software Development Companies India
Framework for building and consuming HTTP services that can reach a broad range of clients including browsers, phones and tablets Use XML or JSON or something else with API. JSON is nice for mobile apps with slow connections For example: Call an API from jQuery and better utilize the client's machine and browser What is ASP.NET Web API? http://www.ifourtechnolab.com/ C# Software Development Companies India
It is built for all the other, non-human interactions website or service needs to support. Think about jQuery code that's making an Ajax request, or a service interface that supports a mobile client In these cases, the requests are coming from code and expect some kind of structured data and specific HTTP Status Codes These two are very complimentary, but different enough that trying to build out HTTP services using ASP.NET MVC took a lot of work to get right Why ASP.NET MVC Web API? http://www.ifourtechnolab.com/ C# Software Development Companies India
Modern HTTP programming model Directly access and manipulate HTTP requests and responses in Web APIs using a new, strongly typed HTTP object model Full support for routes Web APIs now support the full set of route capabilities that have always been a part of the Web stack, including route parameters and constraints Additionally, mapping to actions has full support for conventions, so no longer need to apply attributes such as [HttpPost] to your classes and methods Filters Web APIs now supports filters, including well-known filters such as the [Authorize] attribute ASP.NET Web API Features http://www.ifourtechnolab.com/ C# Software Development Companies India
Content negotiation The client and server can work together to determine the right format for data being returned from an API Provide default support for XML, JSON, and Form URL-encoded formats, and extend this support by adding your own formatters Model binding and validation: Model binders provide an easy way to extract data from various parts of an HTTP request and convert those message parts into .NET objects which can be used by the Web API actions Improved testability of HTTP details Rather than setting HTTP details in static context objects, Web API actions can now work with instances of HttpRequestMessage and HttpResponseMessage Generic versions of these objects also exist to work with custom types in addition to the HTTP types ASP.NET Web API Features (Cont.) http://www.ifourtechnolab.com/ C# Software Development Companies India
Query composition By simply returning IQueryable <t>, Web API will support querying via the OData URL conventions Improved Inversion of Control (IoC) via DependencyResolver Web API now uses the service locator pattern implemented by MVC’s dependency resolver to obtain instances for many different facilities Code-based configuration Web API configuration is accomplished solely through code, leaving config files clean Self-host Web APIs can be hosted in own process in addition to IIS while still using the full power of routes and other features of Web API ASP.NET Web API Features (Cont.) http://www.ifourtechnolab.com/ C# Software Development Companies India
The client is whatever consumes the web API (browser, mobile app, and so forth) A model is an object that represents the data in application. In this case, the only model is a to-do item. Models are represented as simple C# classes (POCOs) A controller is an object that handles HTTP requests and creates the HTTP response ASP.NET Web API Design http://www.ifourtechnolab.com/ C# Software Development Companies India
MVC : Model -> View -> Controller Create a Model Create a Controller ASP.NET MVC Web API http://www.ifourtechnolab.com/ C# Software Development Companies India
It is defined, by default, as api /{controller} / {id} where action is defined by an HTTP method (in global.asax Application_Start method) Routing Table HTTP Method URI Path Action Performed GET /api/products Get All Products GET /api/products/id Get Product b y Id GET /api/products?category=category Get Products by Category POST /api/products Insert Product PUT /api/products/id Update Product DELETE /api/products/id Delete Product http://www.ifourtechnolab.com/ C# Software Development Companies India
The four main HTTP methods are mapped to CRUD operations: Get retrieves the representation of the resource at a specified URI. GET should have no side effects on server PUT updates a resource at a specified URI POST Create a new resource. The server assigns the URI for the new object and returns this URI as part of the response message DELETE deletes a resource at a specified URI Routing Table http://www.ifourtechnolab.com/ C# Software Development Companies India
ASP.NET MVC Web API - Example APIs for crud operation for products http://www.ifourtechnolab.com/ C# Software Development Companies India
Response messages, errors and exceptions are translated to HTTP response status codes For example: POST request should reply with HTTP status 201 (created) DELETE request should reply with HTTP status 204 (no content) But: If a PUT/GET request is done with an invalid id, it should reply with HTTP status 404 (not found) Or if a PUT request has invalid model, it can reply with HTTP status 400 (bad request) Error & Exception Handling http://www.ifourtechnolab.com/ C# Software Development Companies India
By default, all .NET exceptions are translated into an HTTP response with status code 500 (internal error) It is possible to register Exception filters: Error & Exception Handling (Cont.) http://www.ifourtechnolab.com/ C# Software Development Companies India
Like MVC, Web API supports Data Annotations (System.ComponentModel.DataAnnotations) Model Validation http://www.ifourtechnolab.com/ C# Software Development Companies India
Model Validation - Example http://www.ifourtechnolab.com/ C# Software Development Companies India
Create a FilterAttribute Add it to Filters in Global.asax Application_Start Model Validation - FilterAttribute http://www.ifourtechnolab.com/ C# Software Development Companies India
https://www.tutorialspoint.com/asp.net_mvc/asp.net_mvc_web_api.htm https://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api http://www.c-sharpcorner.com/uploadfile/4d9083/how-to-create-web-api-in-asp-net-mvc/ References http://www.ifourtechnolab.com/ C# Software Development Companies India
Questions? http://www.ifourtechnolab.com/ C# Software Development Companies India