Web Api Tutorial Pdf
This book is a hands-on tutorial on ASP.NET Web API. It is a walk through to Web API with tutorials and practical demo applications. Let’s start, by creating a brand new.NET Core 3.0 Web API project named PDFGenerator: After the project creation, we are going to modify the launchSettings.json file to disable our browser to start automatically.
- ASP.NET MVC Tutorial
- ASP.NET MVC Useful Resources
- Selected Reading
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.
When you're building APIs on the Web, there are several ways you can build APIs on the Web. These include HTTP/RPC, and what this means is using HTTP in Remote Procedure Call to call into things, like Methods, across the Web.
The verbs themselves are included in the APIs, like Get Customers, Insert Invoice, Delete Customer, and that each of these endpoints end up being a separate URI.
Let’s take a look at a simple example of Web API by creating a new ASP.NET Web Application.
Step 1 − Open the Visual Studio and click File → New → Project menu option.
A new Project dialog opens.
Step 2 − From the left pane, select Templates → Visual C# → Web.
Step 3 − In the middle pane, select ASP.NET Web Application
Enter project name WebAPIDemo in the Name field and click Ok to continue. You will see the following dialog, which asks you to set the initial content for the ASP.NET project.
Step 4 − To keep things simple, select the Empty option and check the Web API checkbox in the ‘Add folders and core references for’ section and click Ok.
Step 5 − It will create a basic MVC project with minimal predefined content. /download-game-offline-pc-ringan-art-of-war.html.
Once the project is created by Visual Studio, you will see a number of files and folders displayed in the Solution Explorer window.
Step 6 − Now we need to add a model. Right-click on the Models folder in the solution explorer and select Add → Class.
You will now see the Add New Item dialog.
Web Api Tutorial Kudvenkat Pdf
Step 7 − Select Class in the middle pan and enter Employee.cs in the name field.
Step 8 − Add some properties to Employee class using the following code.
Step 9 − Let’s add the controller. Right-click on the controller folder in the solution explorer and select Add → Controller.
It will display the Add Scaffold dialog.
Step 10 − Select the Web API 2 Controller - Empty option. This template will create an Index method with default action for controller.
Step 11 − Click ‘Add’ button and the Add Controller dialog will appear.
Step 12 − Set the name to EmployeesController and click ‘Add’ button.
You will see a new C# file ‘EmployeeController.cs’ in the Controllers folder, which is open for editing in Visual Studio with some default actions.
Step 13 − Run this application and specify /api/employees/ at the end of the URL and press ‘Enter’. You will see the following output.
Step 14 − Let us specify the following URL http://localhost:63457/api/employees/1 and you will see the following output.
Microsoft ASP.NET Web API framework is the best choice for developing HTTP services in more simpler way. It enables us to reach more wider ranger of clients such as browsers as well as mobile devices.In one of my previous web development tutorial about building RESTful service, I explained that the purpose of HTTP is not just acting as a transport layer (for example, in case of SOAP-based WCF service). However, its a very mature platform for developing Web APIs and utilizing its old simple concepts such as HTTP methods, HTTP status codes and URIs etc.
UPDATE: If you are interested further on ASP.NET Core and ASP.NET Core Web API, you can follow below:
More Practical Implementations using ASP.NET Web API are:
- Developing an ASP.NET Web API Expense Management App with AngularJS
- Creating your first SPA Application using AngularJS and Web API having all CRUD Operations.
- Build a Full-Stack web app with ASP.NET Core, Entity Framework Core and Angular 2 & 4
Net Core Web Api Tutorial
Note: You can download a PDF version of the same “A Practical Guide to ASP.NET Web API” here.
So, we can say that using ASP.NET Web API, we can create HTTP services
- those are non-SOAP based like plain XML or JSON string.
- using full features of HTTP.
- reaching broader range of clients (browsers and mobile devices).
Following is the typical ASP.NET Web API processing architecture.
You are designing an ASP.NET Web API application. You need to select an HTTP verb to allow blog administrators to moderate a comment. Which HTTP verb should you use?- A. GET
- B. POST
- C. DELETE
- D. PUT
To further test your ASP.NET Web API skill, Take a Complete FREE Online Test or MCSD Practice Exam: 70-486 (Developing ASP.NET MVC Web Applications). Simply Click Here.
Correct Answer: D
Lets move forward to implement all the above mentioned related features step by step.
- Resources and URIs
- HTTP Methods
- HTTP Status Codes
- HTTP Content
- Internet Media Types
- REST
- JSON & XML
Chapter 1:- Developing your first ASP.NET Web API service
In chapter 1, we will be creating a simple HTTP service using Web API. A step by step approach is used while developing the service and getting results as:
- Creating a Web API Project in Visual Studio
- Preparing a Domain Model
- Adding Controller
- Finally testing results in browser.
Chapter 2:- Performing CRUD operations using ASP.NET Web API service – Part 1
As chapter 1 only focuses getting records using HTTP GET verb only, this chapter provides complete detail understanding of all CRUD (Create, Retrieve, Update, Delete) operations using Web API. Discussion about all related HTTP verbs i.e. GET, PUT, POST, DELETE is provided.
Chapter 3:- Performing CRUD operations using ASP.NET Web API service – Part 2
As we have already developed Web API service in previous chapter, here in this chapter, we will be consuming already created HTTP service using jQuery. Complete code snippet of jQuery for consuming a Web API service is given with detailed understanding of jQuery AJAX call.
Chapter 4:- What’s new in ASP.NET Web API 2
Web API version 2 is released and this chapter briefly overview the top new features of ASP.NET Web API i.e.
- Attribute Routing
- Cross Origin Resource Sharing
- Open Web Interface for .NET
- IHttpActionResult
- Web API OData
Model in MVC framework is a representation of data structure. This Web API Tutorial focuses to understand and implement the data annotation technique for applying validation on a model class for an ASP.NET Web API application.
Chapter 6:- Exception Handling in ASP.NET Web API – Part 1
This chapter discusses about Exception Handling in ASP.NET Web API service. Instead of returning a generic status code i.e. 500 (Internal Server Error), a valid and meaning result should be sent back to client using HttpResponseException type.
Chapter 7:- Exception Handling in ASP.NET Web API – Part 2
To achieve the same purpose, as discussed in previous chapter, for more advanced scenarios: Web API provide Exception Fitlers and focus of the chapter is how to create an Exception Filter and return meaningful response.
Chapter 8:- ASP.NET Web API OData 5.3
Discussing in detail about features of Microsoft ASP.NET Web API OData 5.3 and 5.3.1 beta including:
- Open Entity Type Support
- Major Bug Fixes
- Dynamic Collection Property in Open Type
- More about flexibility to use $levels and $expand queries
- Utilizing OData Core Libraries.
Extras:- Top 10 ASP.NET Web API Interview Questions
For a detailed and comprehensive list of Top 10 most important Interview Questions for Microsoft ASP.NET Web API that every Web Developer MUST Know.
This collection of ASP.NET Web API Tutorial will definitely help developers to understand in more practical way.