Lanka Developers Community

    Lanka Developers

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Shop

    .NET CORE 3.1 Web API For Beginners Part 02 — Reviewing the project files.

    Back-End Development
    webapi c sharp asp.net core programming restful api
    4
    5
    512
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • BuddhikaNelum
      BuddhikaNelum last edited by

      logo.jpg

      image is taken from www.syncfusion.com

      In the previous article, I explained the basics of .Net Core web API, How to create a project and run it using .Net CLI. You can read it here.

      Today as I promised, we gonna take a look at the project files that we have given out of the box and what responsible for getting us the result we saw in the previous article.

      Program.cs

      program.png

      “Program.cs” is the most important file. because it is the starting point of our application. It contains a method called Main. When we hit the “dotnet run” command in the CLI, it’s looking for the “Main ”method in the “Program.cs” class and executes it. In the “Main ”method, it’s calling another method called “CreateHostBuilder” which you can see below the Main method and this responsible for configuring the webserver which is “Kestral ” with some default configurations. The configurations are read from appSettings.json / appsettings.Development.json files and we also provide some additional configurations inside a class called “Startup”.

      “Kestral” is an open-source cross-platform web server for Asp.Net Core.

      appSettings.json / appsettings.Development.json

      appSettings.png

      We can give our application some configurations inside the “ appsettings.json” file or we can use “ appsettings.Development.json” for development mode.

      Startup.cs

      Startup.png

      In the Startup class, we can see a constructer with configurations injected into that. So that we can read configurations we defined in appsettings.json.

      There are another two methods called “ConfigureServices ”and “Configure”.
      The “ConfigureServices ” method is our dependency injection container. We can create and add our own services to this. I’ll explain what is dependency injection and how to write our own services and add those into our application via dependency injection in another article.

      “Configure” is the place where we add middleware. I’ll also explain the use of middleware with another article.

      Controllers

      controller.png

      There is a file called “WeatherForecastController.cs” in the controllers' folder. It is the default controller that comes with the .Net Core web API. What controllers does is, When we start our application it’s going to map all of our endpoints in our controllers so that our API knows where to send the request to.

      launchsettings.json

      launchsettings.png

      There is another JSON file called “launchsettings.json”. When we start the application it also takes a look inside this file for any options. We have our application URL, environment variables, etc.

      These are the main files you need to know. To understand these things I will guide you on how to create our own API endpoints and services in upcoming articles.

      find me on medium - https://dlbnprabath.medium.com/

      1 Reply Last reply Reply Quote 3
      • root
        root Linux Help last edited by

        Awesome bro, keep it up.

        BuddhikaNelum 1 Reply Last reply Reply Quote 0
        • BuddhikaNelum
          BuddhikaNelum @root last edited by

          @root Thanks bro.

          1 Reply Last reply Reply Quote 0
          • Nubelle
            Nubelle Web Development last edited by

            Thanks bro

            1 Reply Last reply Reply Quote 0
            • dev_lak
              dev_lak last edited by

              thanks bro

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post

              1
              Online

              3.7k
              Users

              1.3k
              Topics

              5.3k
              Posts

              • Privacy
              • Terms & Conditions
              • Donate

              © Copyrights and All right reserved Lanka Developers Community

              Powered by Axis Technologies (PVT) Ltd

              Made with in Sri Lanka

              | |