• Overview
  • Employees.DataServices project
  • Creating Web api using asp. Net mvc 6 Introduction




    Download 2.94 Mb.
    bet1/16
    Sana20.03.2020
    Hajmi2.94 Mb.
      1   2   3   4   5   6   7   8   9   ...   16

    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,

    1. Open the Visual Studio 2015, and then Click on file menu in the menu bar.

    2. Click on New, then project, a new project Template will open.

    3. 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.

    4. 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.

    5. 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,

    1. Employees.WebAPI project

    2. Employees.Model project

    3. Employees.Interface project

    4. 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.




    Download 2.94 Mb.
      1   2   3   4   5   6   7   8   9   ...   16




    Download 2.94 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Creating Web api using asp. Net mvc 6 Introduction

    Download 2.94 Mb.