Pages

Build a minimal ASP.Net Core API with Android Studio for Mac

 Minimal API architecture is ideal for building HTTP APIs with fewer dependencies. If you want to use Android Studio Code to create ASP.Net Core API for applications and microservices that have a limited number of features, files, and dependencies.


We previously wrote a blog post about building a minimal API with Android Studio usingASP.Net Core. Building a minimal ASP.Net Core API for your Mac application becomes easy with Android Studio for Mac. In this article, we have mentioned the process of API creation step-by-step. 


Follow the below steps to ensure a hustle-free build of API using ASP.Net Core for web application with C# language. Another approach to creating API is by using controllers. If you are confused about whether to choose between minimal API and controller. 

Overview

We have provided an overview of the ASP.Net Core tutorial, which enables you to create APIs. You can examine various types of data in the response by using the responseType API that is produced by ASP.Net Core for web software development.  



API

Description

Request body

Response body

GET /todoitems

Receive all to-do items

None

Array of to-do items

GET /todoitems/{id}

Receive an item by ID

None

To-do item

DELETE /todoitems/{id}

Delete an item

None

None

PUT /todoitems/{id}

Updating an existing item

To-do item

None

POST /todoitems

Add a new item

To-do item

To-do item

GET /todoitems/complete

Get a completed to-do items

None

Array of to-do items

Prerequisites

Install Visual Studio 2022 for Mac



Step 1: Create an API Project

  1. Start Visual Studio for Mac in your system, and choose File> New Project


  1. Under the Choose a template for your new project dialog:

  •  Choose Web and Console > App> Empty.

  •  Choose Continue

                                           Source: learn.microsoft.com


  1. Follow the below points:

  • Check the box of HTTPS configuration

  • Target framework: .NET 7.0 (or later)

  • Uncheck the box of Do not use top-level statements

  • Choose Continue

                                          Source: learn.microsoft.com


  1. Type the below-given options:

  • Project Name: TodoApi

  • Solution name: TodoApi

  • Choose Create

Step 2: Examine the Code

The following code is contained in Program.cs file.


C#

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();


app.MapGet("/", () => "Hello World!");


app.Run();


The above-mentioned code:

  • Create a WebApplication and WebApplicationBuilder along with preconfigured defaults. 

  • Build an HTTP GET endpoint ‘/’ which returns ‘Hello World!’

Step 3: Run and test the app

Choose Debug> Start Debugging in order to launch your application. Visual Studio for Mac launches a browser and directs navigation to https://localhost:<port> where the tag <port> signifies a randomly chosen port number. 


After successfully running your application, a browser will display the message ‘Hello World!’ The Program.cs file includes a minimal but complete application.

Step 4: Add NuGet packages

  • Start your Visual Studio 2022 for Mac toolbar, and choose Project> Manage NuGet Packages….

  • Type Microsoft.EntityFrameworkCore.InMemory in the search box.

  • Check for Microsoft.EntityFrameworkCore.InMemory in the result window. 

  • Choose Add Package.

  • Navigate to the ‘Select Projects’ window, choose ‘Ok.’

  • Navigate to the ‘License Agreement’ window, choose ‘Ok.’

  • Follow the above-given points to add up Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore package. 


Navigate to our previous blog Minimal API build using ASP.Net Core with Android Studio for steps 5 and 6. Here you will get all the key information related to coding and other key information for ASP.Net Core API.  


No comments:

Post a Comment

Make new Model/Controller/Migration in Laravel

  In this article, we have included steps to create a model and controller or resource controller with the help of command line(CLI). Here w...