|
Creating Web api using asp. Net mvc 6 Introduction
|
bet | 1/16 | Sana | 20.03.2020 | Hajmi | 2,23 Mb. | | #8262 |
Creating Web API using ASP.NET MVC 6
Introduction:
ASP.NET 5 is a new framework which is completely written from the scratch. ASP.NET 5 is an open source web framework for building modern web applications that can be developed and run on Windows, Linux and the Mac. In ASP.NET 5, the web forms, MVC and Web API framework is clubbed in to one framework.
In this tutorial, we will learn how to create a Web API using the ASP.NET MVC6 framework, then How to publish the Web API using the Visual Studio 2015 and finally we will learn how to host the published API in our local IIS.
Create a Web API Project:
In this sample, I’ll be creating an Web API project using ASP.NET MVC 6 . To create a new Web API application follow the below steps,
Open the Visual Studio 2015, and then Click on file menu in the menu bar.
Click on New, then project, a new project Template will open.
Click on Web Template under the Visual C# (if you are going to use VB as a coding language, then choose Web Template under Visual Basic) on the right side.
Give the name of the project (here my project name is Employees.WebAPI) and choose the location where you want to store your application and the click OK.
On New ASP.NET Project window, Choose Web API under the ASP.NET 5 Template.
Overview
Here is the API that you’ll create:
API
|
Description
|
Request body
|
Response body
|
GET /api/employees/getallemployees
|
Get all employees details
|
None
|
List of employees
|
GET /api/employees/getEmployeeById
|
Get an employee by employee ID
|
None
|
Employee object
|
POST /api/employees/addNewEmployee
|
Add employee details
|
Employee
|
List of employees with newly added employee
|
PUT /api/employees/updateEmployeesById
|
Update an existing employee details
|
Employee
|
List of employees with updated employee
|
DELETE /api/employees/deleteById
|
Delete an employee.
|
None
|
None
|
In this example, we will create four projects, Employees.WebAPI project Employees.Model project Employees.Interface project Employees.DataServices project
Create a Model Project,
In Solution Explorer, right click the src folder and select Add > New Project.
In the Add Project dialog, select the Class Library template. Name the project Employees.Model and click OK.
|
| |