Introduction
An API refers to Application Programming Interface in a computer programming language that defines subroutines or instructions for executing a program to complete a task. The API is an interface to connect software or website to the Server any request or any operation cannot perform without the interaction of the API.
A simple way to understand an API is what?
An API is a messenger to establish a connection between software and server. API is used for transferring data from one side to another. That means all sets of operations can be performed with API like user registration details are saved to the database with the API and access the user data from the database with the API.
The API is used to access data from a database with proper connection or request. In real life example, an API is used to create an account with Google, Facebook, Twitter, etc, and to access Google Map on a Website or project is also using a web API.
In a current scenario, there are various platforms available for developing any project like Web applications, Windows desktop applications, android applications, etc. For example, Facebook is available on Android, Web Applications, Desktop Applications, etc but it used the same structure and same database everywhere. Similarly, we use the same method for any platform-dependent project using API. Generally, the API is created for maintaining a database. and all sets of operations are performed on API. The API does not have any front end it could be tested on swagger and postman. The API returns the response only like 200,404,500 etc various responses are returned according to the method. When a request is denied for any region like an account does not exist, the map is not accessed, etc that time API shows an error.
API Request Methods
POST
The Post request is used for submitting a new record into a database.
GET
The Get request is used to display all available records in a table or list.
PUT
The Put request is used for updating the available record from the database.
DELETE
The delete request is used to delete the record from the database.
What is CLI?
The full form of CLI is Command Line Interface in a .NET core command-line interface is a cross-platform command-line tool used to develop and perform various development activities when developing a .Net core application.
Step by step to explain how to create .NET core web API using Command Line
Step 1
To install a .Net in our system.
Step 2
To open a command prompt.
Step 3
To check whether the .NET is installed or not type in the command prompt
Now check which version is installed to type in the command prompt
It shows all versions of dot net core SDK.
Step 4
(I) suppose I’m creating a web API in D drive with the WebAPI folder name.
(II) Now I jump directly into the D drive to type command prompt D:
(III) And move to the WebAPI folder to type the command prompt cd webapi
Step 5
Here I’m creating a WebAPI to type the command prompt dotnet new webapi -n MyWebAPI
Explain the command dot net is language, web API is a type of project, -n is new, MyWebAPI is a Project Name.
Step 6
To check the folder whether the API is created or not.
Before building the API to move the API folder type the command prompt cd MyWebAPI
Step 7
To build the API to type command prompt
Step 8
To run the API to type command prompt
Step 9
To copy the local host path to show output select Ist localhost path and paste the path in the chrome browser by default it shows a page not found because the WebAPI property folder has a launch setting JSON file in a file by default open weather forecast API data.
Step 10
To call the weather forecast controller then shows the output.
Conclusion
Here to directly create a web API using a command prompt because all steps are the same to use any platform like Linux, windows, mac, etc.
No confusion to create API.
If you want any help to type command prompt dot net help it shows all dot net commands to help.