[Update] Web API Tutorial | web api – Pickpeup

web api: คุณกำลังดูกระทู้

ASP.NET Web API Tutorial

Asp.Net Web Api Tutorial

In this tutorial, we will discuss the following topics:

  • What is Web API?
  • Who uses API?
  • ASP.NET Web API features
  • RESTful services
  • Principles of REST API
  • Methods of REST API
  • Implementing REST API Simple application
  • Need for Web API
  • MVC vs. Web API
  • Web API vs. WCF
  • Web API vs. Web Services
  • Web API Security

ASP.NET Web API tutorial provides basic and advanced concepts of ASP.NET. Our ASP.NET tutorial is designed for beginners and professionals both.

What is Web API?

  • Web API is the enhanced form of the web application to provide services on different devices like laptop, mobile, and others.
  • Today, all kind of businesses use the internet as a cost-effective way to expand their business in the international market.
  • Web application helps to exchange information on the internet and also helps to perform a secure transaction on web sites.
  • Web applications are popular as the web browser is available in default, we don’t need any installation of software on computers with operating systems.
  • For example, Facebook (a social networking web application), Flickr (a photo-sharing web application), and Wikipedia are majorly used example of a web application.
  • Technically, a web application consists of two types of scripts:

1) Client-side scripts: JavaScript, HTML, and other client-side scripting languages are used to design the web forms to present information to users.

2) Server-side scripts: ASP and other server-side scripting languages are used to perform business logic and database related operations like storing and retrieving information.

  • A web application is Human-System interaction.
  • Either it can be single page application just to provide information for some business, or it can be a collection of web pages that are used to take some information from the user and providing the services to the user.

Who uses API?

These services can be accessed by different kind of users like:

  • Web Browsers
  • Mobile applications
  • Desktop applications
  • IOTs (Internet of Things)


API stands for the Application Programming Interface.

“ASP.NET Web API is an extensible framework for building HTTP (Hypertext Transfer Protocol) services that can be accessed from any client such as browsers and mobile devices.”

For example, we make a reservation from different web applications like MakeMyTrip, Ixigo or Paytm and all other reservation web applications, but all applications make a reservation using credentials from IRCTC web site only, i.e., user performing reservation must have login credentials of IRCTC web site.

These services can be accessed by different kind of users like:

  • Web Browsers
  • Mobile applications
  • Desktop applications
  • IOTs (Internet of Things)

Web API services are used when the application is to be used on a distributed system.

Web API takes requests from the different type of client devices like mobile, laptop, etc. and sends them to the web-server to process it and returns the desired data to the client.

Asp.Net Web Api Tutorial

Custom Web Application using a different kind of API’s

Web API is System-System interaction, where information from one system is processed by another system, and resultant data is shown to the viewer.

Let’s take another example from Web API examples, we want McDonald’s burger.

Let us suppose McDonald’s only gives permission for takeaways to cooks only and not for others. Here McDonalds-Takeaways (cook) is like an API, which allows other systems (cooks) to access the services and provide desired data.

ASP.NET Web API features

1) ASP.NET Web API is much similar to ASP.NET MVC.

2) It contains similar features as ASP.NET MVC like:

  • Routing
  • Controllers
  • Action results
  • Filter
  • Model, etc.

3) There is a misconception that ASP.NET Web API is a part of ASP.NET MVC framework, while it can be used with any other type of web application.

4) Stand-alone services can be developed using the Web API.

5) ASP.NET Web API framework is widely used to develop RESTful services.

RESTful services

  • Web API is the enhanced form of a web application.
  • SOAP (Simple Object Access Protocol) was an XML based protocol for developing the connected web applications.
  • Problem with the SOAP was that with each request, Metadata is attached with data to be transferred.
  • This Metadata converts small data to heavy data on the server.
  • Web API may or may not be RESTful services, but they are always HTTP based services.
  • REST stands for Representational State Transfer.
  • In REST API, only the state of the object is sent to the server to find the desired result.
  • REST is an architectural pattern for developing an API that uses HTTP as its underlying communication method.

When we are using HTTP based service, for example, BookMyShow app, we need data in managed form like JSON format, XML format.

Client requests for the information by sending parameters using API methods.

Asp.Net Web Api Tutorial

For example, if we want to book a show for which we want to know the details like City, Movie Name, Place, Timing. We will send the state of the object to the web-server, and API will check whether the data is available or not.

If the data is available (the movie is available for that instance), then it will send back the response to the client with the object.

Values of an object are sent to the client, i.e., basically state of an object is sent to the client, so each time you don’t have to create an object.

“REST API is an architectural style as well as an approach for communications purpose that is often used in various web developments.”

It is a stateless, client-server model.

READ  [NEW] MyFedLoan Review: Is MyFedLoan Servicing Worth it? | myfedload.org - Pickpeup

Asp.Net Web Api Tutorial

Principles of REST API

The six principles of REST API are:

  1. Stateless
  2. Client-Server
  3. Uniform Interface
  4. Cacheable
  5. Layered System
  6. Code on demand

1) Stateless: When the request from the client is sent to the server, it contains all the required information to make the server process it. A request may be part of QueryString or URL.

For example, let’s suppose the resource is requested from the URL (Uniform Resource Locator).

Asp.Net Web Api Tutorial

2) Client-Server: Separating the functionality helps to increase user interface portability across multiple platforms as well as extended the scalability of the server components.

3) Uniform Interface: To obtain the uniformity throughout the application, REST has defined four interface constraints for which are:

  • Resource Identification
  • Resource Manipulation using representations
  • Self-descriptive massages
  • And hypermedia as the engine of the web application

4) Cacheable: In order to provide a better performance, applications are made cacheable. It is done by marking the response as cacheable or non-cacheable implicitly or explicitly. If the resource is defined cacheable, then the client cache can reuse response data for equivalence requests.

5) Layered System: The layered system allows an application to be most stable by limiting component behavior. The layered architecture also helps to enhance security as the component at each layer cannot interact beyond each layer they are in.

6) Code on demand: Constraint that is used optionally and least. Analyze and simplify the client by creating a smart application which doesn’t lie on its own code structure.

Methods of REST API

  • Working on web technologies, we work on CRUD applications.
  • In these applications, CRUD is to CREATE, READ, UPDATE, and DELETE a resource.
  • Here, a resource is defined as the desired result. For example: https://in.bookmyshow.com/noida/movies
  • In the above example, the user is looking for movies in city Noida on bookmyshow application, so the resource is the data, the client is looking for.
  • To perform these actions like to create a resource, read a resource, update a resource, or delete a resource, we can use HTTP methods also called as REST methods.

Now the basic CRUD operations are mapped to the HTTP protocols in the following manner:

CRUD Methods
REST API Methods

Method refers to the C(Create) part of the CRUD.
It is used to create a resource.

Method refers to the R(Retrieve) part of the CRUD.
It is used to read a resource.

Method refers to the U(Update) part of the CRUD.
It is used to update a resource.

Method refers to the D(Delete) part of the CRUD.
It is used to delete a resource.

  • REST API is best used for distributed systems.
  • A distributed database is used everywhere, database stores data, on which CRUD (Create, Retrieve, Update, and Delete) operations are performed.

So let’s have an example of getting some dishes from the resource:


Now let’s assume we want some specific dish from resource:


Implementing REST API Simple application

Let’s create a REST API service for students.

  • Firstly open Visual Studio (here we have Visual Studio 2019).
  • Now select Create a new project:

Asp.Net Web Api Tutorial

  • Now select the template ASP.NET Web Application (.NET Framework) with C# and name the project as “WebApiStudentsSample“.

Asp.Net Web Api Tutorial

  • In the ASP.NET Project dialog, select the Empty template and also check Web API option. Click OK.

Asp.Net Web Api Tutorial

  • A default structure generated will be as follows:

Asp.Net Web Api Tutorial

Adding Student.cs class to the Models folder

  • Add a class with the name “Student” to define properties and other business logic. We can also define other logics as validation, data access, etc.
  • Right-click on Models, Select Add option, and then select Class and give a name to the class as “Student.cs

Asp.Net Web Api Tutorial

Add the following code to define properties for student class:

Adding StudentControllers.cs class to Controllers folder

  • Controller class handles HTTP request from the client, which may be a desktop application, mobile device, and browser.
  • Right-click on Controllers, Select Add option, and then select ‘Controller..‘.

Asp.Net Web Api Tutorial

Add Scaffold window will open then Select Web API2 Controller ?Empty template.

Asp.Net Web Api Tutorial

  • After selecting Scaffolding template, Add controller window will open and give a name to the class as “StudentController“.

Asp.Net Web Api Tutorial

Note: We can see that the controller class inherits the System.Web.Http.ApiController class instead of the Controller class.

  • Scaffolding creates a “StudentController.cs” class inside the controller folder.

Now implement methods to perform CRUD operations. Let us assume we want all student details and also details for some specific student.

Now add following code:

In the StudentController class controller, you can see that the method “GetAllStudents” return the list of all students and the method “GetStudentDetails” returns the detail of single student.

In the following table, you can understand how controller use route URL to perform CRUD action.

Controller Method
Route URI(Uniform Resource Identifier)

/api/ student
/api/ student /id

Run The Web API

To run a Web API, firstly press F5 or Ctrl+F5 or Click on IIS express run icon then the browser will open with the URL like https://localhost:44329/

Now to find the list of all students edit the URL as https://localhost:44329/api/student

Asp.Net Web Api Tutorial

To fetch the details of a single student, Edit the URL as:


Asp.Net Web Api Tutorial

Need for Web API

  • A Web API helps to access service data from different internet devices like browsers, mobile apps, and other devices.
  • Helps to work on RESTful web services.
  • Helps to develop light weighted and maintainable Web Services.
  • Used to create both types of services RESTful and non-RESTful services.
  • Also supports JSON, XML, and other data formats.
  • Helps to develop services supporting all features of HTTP services such as like caching, request/response headers, versioning, etc.

MVC vs. Web API

Differences between ASP.NET API and ASP.NET MVC are as follows:


Helps to develop web applications that process the request and sends both views and data.
Helps to develop HTTP services (RESTful and non-RESTful services) that process the request and returns data only, not a view.

Represents resultant data in JSON format using JsonResult.
Return data in particular format like JSON, XML or any other format

A request is mapped to actions name.
A request is mapped to HTTP verbs in Web API

READ  [NEW] 워킹데드 시즌11 2화. <여러분이 놓쳤을지도 모르는 16가지> | 워킹데드 유진 - Pickpeup

Model binding, routing, and other features are defined in System.Web.Mvc.
Same features are available in Web API, and these features are defined in System.Web.Http assembly.

MVC usually interact with the views to provide final output
Supports feature of content-negotiation, i.e., deciding the best format for response data that is compatible with the client machine.

Web API vs. WCF

Differences between ASP.NET WCF and ASP.NET Web API are as follows:


Content format
Web API supports any media format like XML, JSON, etc.
WCF supports SOAP-based services and XML format.

Web API supports IIS hosting, Self-hosting
WCF supports works activation services and also IIS hosting, Self-hosting.

MVC features
ASP.NET Web API supports features like controllers, routing, action, etc. same as MVC.
Like MVC, WCF does not provide any features like controllers, routing, filter, auction results, etc.

Web API supports HTTP protocol.
UDP, HTTP, and custom transport protocol are supported.

Use of model
Uses HTTP verbs as methods called as CRUD operations
ServiceContract attribute defines a Service Contract that contains operations.
OperationContract attribute defines the operations that will be used.
DataContract attribute defines the properties or types that will be transferred between the parties.

Web API vs. Web Services

Differences between Web API and Web services are as follows:

Web services

Hosting is done within an application or IIS.
Hosting is done on IIS.

Open Source
Web API is open-source, and it can be used by any client that supports JSON or XML.
Web service is not open-source but can be used by any client that supports XML.

Web API is light-weighted architecture and good for devices which have limited bandwidth, like mobile devices.
It requires a SOAP protocol to receive and send data over the network, so it is not light-weight architecture.

It supports the HTTP protocol: URL, Request/Response Headers, versioning, caching, content formats.
It supports the HTTP protocol only.

Web API Security

ASP.NET Web API Authentication and Authorization are important concepts for Web API security.

Suppose a web API is created, and the access to the API is for some specific users, and also different operations are available for different users.

  • Authentication is to validate the credentials for the user and identify them.
    For example, a user login with his username and password and server authenticate the user by a password.
  • Authorization is to define the access level for each user to perform a different operation.
    For example, a person is allowed to create a resource but not to delete the record.

If a request requires authentication in web API, but the client does not provide the credentials in the request header, then the server will return 401 (Unauthorized).


Before learning Web API, the user must have basic knowledge of Http methods, C# properties also Knowledge of MVC will be plus point.


This tutorial is for beginners and professionals to learn Web API and RESTful services.


This tutorial is available in a simple and easy language still, if there is any confusion, kindly post the doubt in the contact form.

What is ASP NET Web API

If you are a foodie like me, I am sure you will enjoy the recipes on my friend’s YouTube channel. If you find them useful, please subscribe and share to support her. She’s really good at what she does.
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Code samples and text version of the video
Dot net and sql server video tutorial playlists
All ASP.NET Web API Text Articles and Slides
In this video we will discuss
1. What is ASP.NET Web API
2. What are RESTful services
3. Difference between WCF and Web API. When to use WCF over ASP.NET Web API and vice versa
What is ASP.NET Web API ?
The term API stands for ‘Application Programming Interface’. ASP.NET Web API is a framework for building Web API’s, i.e. HTTP based services on top of the .NET Framework. The most common use case for using Web API is for building RESTful services. These services can then be consumed by a broad range of clients like
1. Browsers
2. Mobile applications
3. Desktop applications
4. IOTs
What are IOTs
The term IOTs stands for Internet Of Things. Internet Of Things are the objects or devices that have an IP address and can communicate over the internet with other internet enabled devices and objects. Examples for IoT include security systems, electronic appliances, thermostats, cars etc…, in addition to desktops, laptops, and smart phones.
One important thing to keep in mind is that, though ASP.NET Web API framework is widely used to create RESTful services, it can also be used to create services that are not RESTful. In short, ASP.NET Web API framework does not dictate any specific architeture style for creating services. In this video, we will discuss creating RESTful services from scratch using ASP.NET Web API framework.
What are RESTful services
REST stands for Representational State Transfer. REST was first introduced in the year 2000 by Roy Fielding as part of his doctoral dissertation. REST is an architectural pattern for creating an API that uses HTTP as its underlying communication method. The REST architectural pattern specifies a set of constraints that a system should adhere to. Here are the REST constraints.
1. Client Server constraint
2. Stateless constraint
3. Cacheable constraint
4. Uniform Interface
Another concept related to Uniform Interface is HATEOAS. HATEOAS stands for Hypermedia as the Engine of Application State. All this means is that in each request there will be set of hyperlinks that let’s you know what other actions can be performed on the resource. If this is not clear at the moment, don’t worry, we will discuss this in a later video.
There are 2 other constraints
Layered System
Code on Demand (optional)
Difference between WCF and Web API. When to choose one over the other?
WCF (Windows Communication Foundation) One of the choices available in .NET for creating RESTful services is WCF. The problem with WCF is that, a lot of configuration is required to turn a WCF service into a RESTful service. The more natural choice for creating RESTful services is ASP.NET Web API, which is specifically created for this purpose.
WCF is more suited for building services that are transport/protocol independent. For example, you want to build a single service, that can be consumed by 2 different clients Let’s say, a Java client and .NET client. Java client expects transport protocol to be HTTP and message format to be XML for interoperability, where as the .NET client expects the protocol to be TCP and the message format to be binary for performance. For this scenario WCF is the right choice. What we do here is create a single WCF service, and then configure 2 end points one for each client (i.e one for the Java client and the other for the .NET client). If you are new to WCF, please watch our WCF video series. I will have the link available in the description of this video.
There is nothing wrong to use WCF to create RESTful services. It’s just that it’s a bit more complex and configuration can be a headache. If you are stuck with .NET 3.5 or you have an existing SOAP service you must support but want to add REST to reach more clients, then use WCF.
If you don’t have the limitation of .NET 3.5 and you want to a create brand new restful service then use ASP.NET Web API.

READ  [NEW] Canvas, Slip-On & Skate Shoes | van - Pickpeup

นอกจากการดูบทความนี้แล้ว คุณยังสามารถดูข้อมูลที่เป็นประโยชน์อื่นๆ อีกมากมายที่เราให้ไว้ที่นี่: ดูความรู้เพิ่มเติมที่นี่

What is ASP NET Web API

Bài 27 – REST API

Chuỗi bài giảng: Xây dựng NodeJS web server sử dụng Express
🍣Chia sẻ vì cộng đồng sinh viên Việt Nam
🍣Các bài giảng: https://coders.tokyo/tuts/
🍣Blog: https://coders.tokyo/blog/
🍣Đăng ký tham gia học nhóm: http://bit.ly/coderstokyosignup
🍣Live stream 2 tuần một lần: http://bit.ly/coderstokyofbevent
Facebook Page: http://fb.com/coders.tokyo
Youtube Playlist: https://www.youtube.com/c/CodersTokyo
Website: https://coders.tokyo/
Instagram: https://www.instagram.com/Coders.Tokyo
coders tokyo coders_tokyo free_coding_class nodejs express CodersTokyo

Bài 27 - REST API

Learn Angular 10, Web API \u0026 SQL Server by Creating a Web Application from Scratch

Source Code: https://github.com/ArtOfEngineer/Angular10WebAPITut
Related Tutorials:

React JS + Python Django + SQLite fullstack app

React JS + .NET Core Web API + Microsoft SQL full stack app

.NET Core API + Vue JS + Microsoft SQL fullstack web app

ASP .NET Core Web API + Microsoft SQL CRUD APIs

ASP .Net Core Web API + MySQL | CRUD APIs Tutorial

.NET Core Web API + PostgreSQL | CRUD APIs

.Net Core Web API + MongoDB CRUD APIs

Python Django + SQLite | REST APIs

Python Django + PostgreSQL | REST API Tutorial

Python Django + MySQL CRUD API Tutorial

Python Django + MongoDB CRUD API Tutorial

Python Django + Microsoft SQL Server CRUD API Tutorial

 Kite is a free AIpowered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. https://www.kite.com/getkite/?utm_medium=referral\u0026utm_source=youtube\u0026utm_campaign=artofengineer\u0026utm_content=descriptiononly
Python and Angular app tutorial video: https://youtu.be/1Hc7KlLiU9w
Learn to create a simple web application from scratch using Angular 10, ASP .NET Web API and Microsoft SQL Server.
1:12 : Install SQL Server and SQL Server Management Studio.
4:26 : Install Visual Studio.
5:50 : Install Visual Studio Code.
6:56 : Install POSTMAN.
7:44 : Install Node JS.
8:43 : Install Angular 10.
10:01 : Create DB and Tables in Microsoft SQL Server.
16:51 : Create .NET Web API Project.
20:38 : Force API to return JSON response only.
22:49 : Enable CORS.
24:52 : Create Models.
27:22 : API for Department Screen : GET.
33:13 : API for Department Screen : POST, PUT and DELETE.
36:48 : APIs for Employee Screen.
43:30 : Upload Photo API.
46:32 : Angular Project Intro.
48:02 : Create Angular 10 Project.
51:38 : Generate Components and Services in the Angular Project.
53:57 : Add Service methods to consume APIs.
59:32 : Routing in Angular.
1:01:42 : Add Bootstrap to our Angular App.
1:02:45 : Navigation Menu using Bootstrap.
1:04:50 : Show Department Screen with Bootstrap Table.
1:08:49 : Modal Pop Up Window using Bootstrap.
1:12:39 : Add and Edit Pop Up Screen for Department.
1:17:24 : Delete Department.
1:19:12 : Show Employee Screen with Bootstrap table.
1:22:31 : Upload Photo, Add and Edit Employee Details Pop Up Screen.
1:31:34 : Custom Sorting and Filtering to our Bootstrap table.
1:36:41 : How to get Publishable files of .NET Web API and Angular.

Learn Angular 10, Web API \u0026 SQL Server by Creating a Web Application from Scratch

Sử dụng Postman làm việc với REST API

Trong video này mình hướng dẫn các bạn sử dụng Postman làm việc với REST API ở góc độ cơ bản.
🔥 Hãy chia sẻ các khóa học để mọi người được học MIỄN PHÍ ❤️
🔥 Truy cập http://fullstack.edu.vn (miễn phí) để làm bài tập và quản lý được tiến độ học của bạn. Trong tương lai còn giúp bạn có hồ sơ đẹp trong mắt Nhà Tuyển Dụng.
🔥 Tham gia nhóm Học lập trình tại F8 trên Facebook: https://www.facebook.com/groups/f8official/
hoclaptrinh mienphi frontend backend devops

1. Khóa Javascript cơ bản: https://fullstack.edu.vn/courses/javascriptcoban
2. Khóa HTML, CSS: https://fullstack.edu.vn/courses/htmlcss
3. Khóa Responsive web design: https://fullstack.edu.vn/courses/responsivewebdesign
4. Khóa Xây dựng web với NodeJS \u0026 ExpressJS: https://fullstack.edu.vn/courses/nodejs

1. Học lập trình: http://fullstack.edu.vn
2. Viết CV xin việc: http://mycv.vn
3. Danh sách phát Youtube: https://www.youtube.com/channel/UCNSCWwgWrwmoE3Yc4WmJhw/playlists

1. Facebook: https://fb.com/sondnmc
2. Email: sondnf8@gmail.com
Yêu các bạn ❤️

Sử dụng Postman làm việc với REST API

.NET Core Web API с нуля профессионально

Разработка ASP NET Core Web API с нуля профессионально. Видео 1. Обзор
Что мы будем делать: разрабатывать web api для работы с заметками, с использованием таких технологий и инструментов как: чистая архитектура, ASP NET Core 5, EF Core 5, Swagger, IdentityServer4, C, SQLite, Fluent Validation, XUnit, NSwag Studio, Serilog, Automapper, MediatR, CQRS.
Мы пройдемся по всем основным этапам разработки web api и в итоге получим масштабируемый, легко поддерживаемый проект Web API, сделанный с использованием good practices.
Мы в Telegram: https://t.me/platinum_tech_talks
Чат для общения и вопросов: https://t.me/platinum_chat
Business vector created by vectorjuice: https://www.freepik.com/vectors/business

.NET Core Web API с нуля профессионально

นอกจากการดูบทความนี้แล้ว คุณยังสามารถดูข้อมูลที่เป็นประโยชน์อื่นๆ อีกมากมายที่เราให้ไว้ที่นี่: ดูวิธีอื่นๆMusic of Turkey

ขอบคุณมากสำหรับการดูหัวข้อโพสต์ web api

Leave a Comment