Consuming a Standard API: An MVC Real Estate Example
Jose Maria Iriarte

Jose Maria Iriarte @josemariairiarte

About: I explore software, cognition, and creativity. I'm a bilingual English-Spanish .NET developer with experience in C# application development using .NET Framework and .NET Core.

Location:
Buenos Aires, Argentina
Joined:
Oct 15, 2022

Consuming a Standard API: An MVC Real Estate Example

Publish Date: Aug 23 '23
5 1

In this article, we will survey the process of consuming a .NET API service using a real estate application as an example.

Throughout this guide, we will delve into the integration of a .NET MVC application with an existing API (a .NET API app which is included in the repository).

GitHub logo tigerbluejay / MVC-App-Consuming-BARE-API

This project presents an ASP.NET MVC application developed using .NET 7, designed to consume the Buenos Aires Real Estate (BARE) API. It displays apartment complex and apartment unit information, supports full CRUD operations, and integrates .NET Identity for user registration and login. It leverages AutoMapper 12.0, EF Core 7 and SeriLog

MVC App Consuming Buenos Aires Real Estate (BARE) API

This project is an ASP.NET MVC application designed to interact with the Buenos Aires Real Estate (BARE) API—a service that exposes apartment unit rental information across the City of Buenos Aires. The application enables users to perform full CRUD operations on data retrieved from the API, as well as send new data back to the service. It serves as a practical example of consuming a RESTful API from a structured MVC frontend while handling real-world real estate data.

Disclaimer

Note: There is another repository containing the standalone implementation of the Buenos Aires Real Estate API. It can be found here. Note that the standalone implemnetation has some differences with the Buenos Aires Real Estate API that is part of this project. This is so, as changes were made during the development of the MVC App in the Buenos Aires Real…

The MVC application will facilitate actions such as reading, creating, updating, and deleting information via API service calls, all within a user-friendly UI.

Let's break down the components and steps involved in this integration.

Project Structure

The MVC API-Consuming Service Solution comprises three essential projects:

  • MVC Web Project: This houses the core functionality of the application.
  • Models Project: This project contains the models and DTOs (Data Transfer Objects) that mirror those of the API.
  • Utilities Project: This project provides auxiliary code to support object mapping functionalities (using the AutoMapper package).

Project Structure - Solution Explorer

Integration Overview

The MVC app communicates with the API endpoints to perform CRUD (Create, Read, Update, Delete) operations on information related to Apartment Complexes and Apartment Units. Notably, this information is not stored directly in the MVC app's database. Instead, it is available through the API endpoints of the API app, which does itself then communicate with its own database.

Landing Page

User Interface and Operations

Users access the application from the main menu on the home page. They can visualize information about Apartment Complexes and Apartment Units. Interaction with the API occurs through a set of services defined within the MVC app. Users can perform CRUD operations after registering and logging in.

Login

Manage Apartment Complexes

Update Apartment Complex

Authentication and Authorization

The MVC app incorporates an Authentication Service responsible for sending user credentials and login tokens to authenticate users for API consumption. Communication is managed through LoginRequestDTO and LoginResponseDTO. The implementation of sessions enables the MVC app to recognize and maintain user login status.

API endpoints are restricted to logged-in users with the "admin" role, which is the default role for all users. Similarly, certain pages within the MVC app for performing CRUD operations are restricted to "admin" role users.

MVC App Components

The MVC app consists of three main pillars:

  1. Authentication Functionality: Handles user registration and login.
  2. Apartment Complex Functionality: Manages CRUD operations for apartment complexes.
  3. Apartment Unit Functionality: Manages CRUD operations for apartment units.

Manage Apartment Units

Delete Apartment Unit

Each pillar (Auth, ApartmentComplex, ApartmentUnit) is supported by components:

  • Controllers: These direct traffic between views and services, invoked based on the requested URL. There's a controller for each pillar.
  • Views: User interfaces that display information and receive input. Views gather information, such as login credentials or data for updating/creating apartment complexes.
  • DTOs: These mirror the DTOs defined in the API project, facilitating seamless communication between views, controllers, and services.
  • Services: Each pillar has a dedicated service, and they inherit from a base service. Services configure requests, handle serialization/deserialization, and interact with API endpoints.

Relationship with the API Project

The API Project is integrated into the solution as four separate projects. A detailed discussion of the API Project can be found in its own repository's readme file (that is, there exists a near duplicate repository containing only API related code).

GitHub logo tigerbluejay / Buenos-Aires-Real-Estate-API

This project presents a Real Estate API., developed using .NET 7 and leveraging Entity Framework Core 7 for data access. In addition is uses Swagger 6.4, Automapper 12.0 and Open API 7.0. It adopts a layered architecture, clean separation of concerns, and adheres to best practices in API design.

Buenos-Aires-Real-Estate-API

The Buenos Aires Real Estate API is a RESTful web service built to manage, query, and serve real estate property data within the Buenos Aires region. Designed with scalability and clean architecture in mind, it provides a robust backend foundation suitable for integration with front-end applications or data-driven services. This project is ideal for developers looking to understand or contribute to modern API development using the latest .NET ecosystem tools.The Buenos Aires Real Estate API is a RESTful web service built to manage, query, and serve real estate property data within the Buenos Aires region. Designed with scalability and clean architecture in mind, it provides a robust backend foundation suitable for integration with front-end applications or data-driven services. This project is ideal for developers looking to understand or contribute to modern API development using the latest .NET ecosystem tools.

Project Structure

The API Service Solution is comprised of four…

Minor discrepancies exist between the standalone API Repository and the one integrated with the MVC App, primarily related to data types within DTOs and Models. Despite these differences, approximately 99% of the projects' code remains consistent, so reading the standalone API's documentation will be of great use in understanding the code in the MVC App.

The standalone GitHub repo's readme.md file offers a comprehensive treatment of the API Project. Feel free to explore this file, as well as the standalone project, to gain a deeper understanding of the API integration.

Also if you wish, you may check out my post dealing with this project: Navigating a Standard .NET API: A Real Estate Example

In Closing

By exploring the github repo linked at the beginning of the article (the MVC App and its corresponding API), you can gain insights into effectively consuming a .NET API service within a real-world context.

Take the Next Step with API Integration

If this article helped you understand how to consume a .NET API service in a real-world application, here's how you can continue your journey:

📁 Explore the GitHub Repository – Dive into the repository to examine the MVC app and the API integration. Follow along with the code to reinforce your understanding of consuming and interacting with APIs in .NET.

💡 Share the Knowledge – Know someone who’s learning to work with .NET APIs? Share this guide with them to help them accelerate their learning and improve their skills.

🖥 Start Coding – The best way to grasp these concepts is by getting hands-on. Take the provided code and experiment with adding new features or integrating other APIs.

👍 Like the Repository – If you find the project helpful, give it a thumbs-up! This will help others discover the repository and benefit from it too.

By engaging with this tutorial and project, you'll build a strong foundation in .NET API integration, ready to implement these skills in real-world applications.

Comments 1 total

  • Leowhyx
    LeowhyxAug 24, 2023

    Intresting post

Add comment