0% found this document useful (0 votes)
5 views4 pages

Task2_ Web Application and RESTful API DevelopmentWeb Application and RESTful API Development

The document provides an overview of web application and RESTful API development using the MVC architecture, detailing the roles of controllers, models, and views in data handling and validation. It outlines the steps for creating a Web API in ASP.NET Core, emphasizing the importance of structure, security, and data validation. Additionally, it highlights the significance of connected services, dependencies, and the Program.cs file in both Web API and MVC setups.

Uploaded by

gabopik18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Task2_ Web Application and RESTful API DevelopmentWeb Application and RESTful API Development

The document provides an overview of web application and RESTful API development using the MVC architecture, detailing the roles of controllers, models, and views in data handling and validation. It outlines the steps for creating a Web API in ASP.NET Core, emphasizing the importance of structure, security, and data validation. Additionally, it highlights the significance of connected services, dependencies, and the Program.cs file in both Web API and MVC setups.

Uploaded by

gabopik18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Web Application and RESTful API Development

Web Application Basics

When using MVC we are forced to learn its main components such as controllers,
models and views. MVC offers a communication where the controller can obtain
information from the models and supply that data to the views, this is the most
common form of communication in MVC. Now the views cannot request information
from the models directly, they must create a request that is analyzed by the specific
controller of that view, this controller is responsible for consulting the corresponding
model and based on the logic that is detailed in said models, the information is
provided to the view upon returning as a response.
We can see an example of this in the part of the forms and in the data that the user
wants to process. Once we are located in our form in the view, it will ask us for
certain data that is necessary for the logic of the application, in a hypothetical case, if
we are registering a new user to our application we must register all their personal
information since the system forces us to enter that information. If there are fields
such as email or age, through a component of the models that we call User we can
assign certain validations to these fields, for example that the age has to be over 18
years old and under 75 years old, or that the user actually enters a valid email that
has the corresponding signs. We can carry out all these types of validations both on
the model side and on the controller side.
An example of how we can limit an age range is as follows: we type in our model the
Age property [Range(18, 60)]. This means that the age will only allow us to enter
values ​between 18 and 60 but not those that are less than 18 or more than 60 years
old.In the same way, if we use a login view, through controllers we can verify that the
data is correct for the user who is trying to enter the application and also save the
session.

RESTful API Creation

When we want to create our Web API we must always take into account the
language on which we want our service to be based. Once we have selected our
programming language, all that remains is to start typing the code. A facility that
ASP.NET Core offers us is that it is more focused on the creation of this type of
services since it provides us with many tools that help us both visually and at the
structuring level, since it becomes easy to read and understand. Let's review the
step by step in creating the Web APIs in ASPE.NET Core:

●​ We open the Visual Studio Community application


●​ We click on the New project option and select the ASP.NET Core Web API
option. By selecting this option, visual studio will generate all the folders and
files necessary for the operation of our service.
●​ Once our project is created we will see a folder structure in which we will find
the controllers and models. If we want to create controllers we can easily add
them with the facilities offered by the Visual Studio tool.
●​ When creating our controllers we must also take into account our models
since these carry the logic of the service, the data that will be requested and
what type of data we are going to work with.
●​ When we press the button to start our Web API we can see how through the
browser a friendly interface is displayed that contains information from our
Web API, this information is made up of the links that our controllers have, for
example if we want to obtain the information of our users we must type the
correct link in our browser such as 'api/users/', or if we want to obtain a
specific user we can do it in the same way but sending the ID of the user we
need, in this way 'api/users/1'.
●​ In this way we ensure that other applications can consume our service, these
links are created by our controllers, the way in which these links are
generated is automatically but we could also customize these links in the way
that is most useful for us to work with.
●​ When receiving a request from a client through an application, this application
makes the request through HTTP with the links that are generated from the
controllers. Given this, we can place restrictions so that the application that
makes the query meets certain parameters. These parameters offer greater
security to our Web API since they allow us to filter in some way users who
have permitted access to our services.

Code Examples

Now we are going to illustrate some code examples that will be helpful to better
understand the structure of this type of projects:
Web API Project

As you can see, a basic Web API is structured by certain components:

●​ Connected services, these can be cloud services or databases.


●​ Dependencies, which refers to the libraries that we have installed in our
project, which can be installed through the NuGet package manager.
●​ The controllers and models, which are the essential part of the project where
the controllers handle user requests through HTTP and the models provide
the logic that the data must handle.
●​ The Program.cs file is an essential file, through it we can implement certain
requirements that we will need in our entire application.

MVC Setup

In the MVC configuration we can find the


following:

●​ Connected services, these can be


cloud services or databases.
●​ Dependencies, which refers to the
libraries that we have installed in our
project, which can be installed through the
NuGet package manager.
●​ The Program.cs file is an essential file, through it we can implement certain
requirements that we will need in our entire application.
●​ The controllers that are responsible for managing the actions that the user is
going to perform, receiving the data logic that comes from the models and
supplying the views with the required data.
●​ The models that carry the business logic, how the data will behave and what
restrictions or validations we can manage in our application.
●​ The views are responsible for displaying the information that they themselves
request through the controllers, it is the part with which the user will interact
while using our application.

Data Validation

Data validation is a fundamental part of the models since these will define how we
are going to work with the information that comes to us as well as what type of
information we accept. There are many types of validations that we can do and use
in our applications, this way we will be able to manage the information in a format
that is more acceptable to us, either due to database restrictions or because it is the
easiest way to do it.

You might also like