Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Programming APIs with C# and .NET
Programming APIs with C# and .NET

Programming APIs with C# and .NET: Develop high-performance APIs that ensure seamless application communication and enhanced security

Arrow left icon
Profile Icon Jesse Liberty Profile Icon Joseph Dluzen
Arrow right icon
€8.99 €26.99
eBook Nov 2024 166 pages 1st Edition
eBook
€8.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Jesse Liberty Profile Icon Joseph Dluzen
Arrow right icon
€8.99 €26.99
eBook Nov 2024 166 pages 1st Edition
eBook
€8.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €26.99
Paperback
€33.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Programming APIs with C# and .NET

Getting Started

Let’s start by making sure you’re in the right place. This is a book about creating Application Programming Interfaces (APIs) using .NET. Along the way, we will look at a very simple backend (database) and frontend (user interface) and the tools we use to create and test APIs.

The core responsibility of an API is to decouple an application (web, mobile, and so on) from the backend (database, another API, and more). The API sits between the frontend (the user interface to your application) and the backend (for our purposes, a database).

In this chapter, we’re going to cover the following main topics:

  • What software you will need
  • How to obtain the software you need
  • Installing Visual Studio

Technical requirements

To proceed through this book, you will need a computer running Windows (10 or 11) and an internet connection. It is best if your computer has at least 16 GB of memory, and, of course, you’ll need room on your disk for the software and for the code you will write.

You can create APIs on any platform (e.g., Linux) and use any development environment (e.g., Visual Studio Code instead of Visual Studio). This book, however, will focus on Visual Studio and Windows as they are the most popular and arguably the most powerful way to create .NET APIs.

The code files for this book are available in the book’s GitHub repository: https://github.com/PacktPublishing/Programming-APIs-with-C-Sharp-and-.NET.

Where does the API fit in?

When you are creating a decoupled application, your principal parts are:

  • The front end
  • The back end
  • The middleware

A typical front end might be a web application, a mobile application, or other ways of displaying data.

A typical backend might be a database or another service.

The middleware sits between the front end and the back end. The most important middleware is the API. The job of the API is to ensure that the front end and back end are decoupled – that is, you can modify one without affecting the other. This is simply good programming practice and will save you hours (or months) of rewriting should either of these change (which they will!).

The players

Typically, the backend and the frontend are created by different teams, though, of course, you can have one developer creating it all. We’re also going to restrict our backend to a simple database, though any source of data can be a backend. Finally, we’re not going to build a full frontend (that would be a distraction from the point of this book) but, rather, we’re going to use a tool, Postman, to mimic a frontend. There will be more on Postman throughout this book.

Getting set up

You can create your backend, API, and frontend on any operating system you like. For this book, we’ll be creating all three on Windows, using Visual Studio 2022, the latest Postman, and Dapper as a simple Object Relational Mapper (ORM) to make our lives easier. There are a few other simple tools we’ll be using, so let’s get you set up.

Downloading the free software you need

To get started, if you don’t have Visual Studio installed, go to https://visualstudio.com and click on Downloads (this site changes frequently but the basic steps remain the same). You have three choices of which version to download: Community, Professional, and Enterprise. The Community version is free and will provide all you need to follow along in this book.

When you click on your choice, Visual Studio Setup will download to your downloads directory. Double-click on it and click on Yes at the security prompt. The installer will update itself and then will begin the installation. This can take a little while, but don’t go away as you have some selections to make.

Note

If you have Visual Studio installed but for some reason want to install the Community Edition as well, that is no problem as they can run side by side.

A menu will appear similar to Figure 1.1 (if it does not, click Modify).

Figure 1.1 – Setting up Visual Studio: please note that this screenshot intends to show the layout, so text readability is not essential

Figure 1.1 – Setting up Visual Studio: please note that this screenshot intends to show the layout, so text readability is not essential

Be sure that ASP.NET and web development is checked. Scroll down and check Data storage and processing (if you are short on disk space, skip this one). Once you are satisfied, click on Install while downloading and then click on Modify.

SQL Server will be installed for you, as will SQL Server Management Studio (SSMS). You will typically interact with SQL Server through SSMS. We will look at how to work with this tool, and all the others, as we go.

Your next tool is Dapper. This is a small, lightweight ORM (often called a micro-ORM) that does one important part of the work of the much bigger SQL platform, Entity Framework, but with much less overhead. Specifically, Dapper will map queries to objects.

Since our needs will be minimal, Dapper will be more than enough. You can read more about Dapper here: https://www.learndapper.com/.

We will mimic our user interface with Postman, which we will also use for end-to-end testing. You can get the latest version of Postman at https://postman.com/downloads. You can also access Postman through your browser, but we’ll be using the downloaded version.

Postman is surprisingly powerful, and we will review how we will use it as we go along. That said, we will only scratch the surface of what you can do with this tool, so at some point, you may want to read the documentation.

We will be using Swagger for documentation (see Chapter 4), and the built-in logger functionality for (surprise!) logging errors and issues that will not be surfaced to the user, but which will be useful for you as the programmer.

Summary

In this chapter, you saw what software you will need, how to download it, and how to install it. All of the software we’ll be using in this book is free. In the next chapter, we will see the example application that we’ll build to illustrate a meaningful use of an API.

You try it

Be sure to download and install all of the software described if you want to follow along as we create the API.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn API design principles and architecture for high-performance applications
  • Develop robust APIs using best practices for security, scalability, and maintainability
  • Implement both traditional and minimal APIs with real-world scenarios
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

APIs are at the heart of modern software development, enabling seamless communication between applications. In the C# and .NET ecosystem, mastering API development is key to building scalable, reliable systems that meet both client and enterprise needs. Written by C# and .NET experts Jesse Liberty and Joseph Dluzen, this book draws on their extensive experience as hands-on programmers to equip you with the tools, techniques, and best practices for creating powerful APIs. Starting with API fundamentals, it covers everything you need to design, build, and consume APIs using .NET technologies such as ASP.NET Core, and explores both controller and Function API implementations. You'll integrate essential tools such as Postman for testing to streamline your development workflow. Through practical examples and exercises, the book guides you from database creation to deploying APIs on Azure. By the end of this book, you’ll have gained real-world skills to develop secure, high-performance APIs that scale with your applications for both personal projects and enterprise-level systems.

Who is this book for?

This book is for .NET developers, software engineers, and backend developers looking to master API development using C# and ASP.NET Core. It caters to those with a basic understanding of C# and familiarity with the .NET ecosystem. Even though no prior experience with API frameworks is required, knowledge of ASP.NET Core will be helpful.

What you will learn

  • Understand core API concepts and how to apply them in .NET projects
  • Design RESTful APIs with a focus on scalability
  • Build APIs with ASP.NET Core
  • Explore alternative options for API development using Azure Functions, including stateful workflows with Durable Functions
  • Integrate databases into API projects, ensuring efficient data flow
  • Implement security measures such as authentication and authorization
  • Deploy APIs to Azure and learn the essentials of cloud integration

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 22, 2024
Length: 166 pages
Edition : 1st
Language : English
ISBN-13 : 9781803231099
Vendor :
Microsoft
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 22, 2024
Length: 166 pages
Edition : 1st
Language : English
ISBN-13 : 9781803231099
Vendor :
Microsoft
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
Banner background image

Table of Contents

13 Chapters
Chapter 1: Getting Started Chevron down icon Chevron up icon
Chapter 2: What We’ll Build Chevron down icon Chevron up icon
Chapter 3: Implementing with REST Chevron down icon Chevron up icon
Chapter 4: Documentation with Swagger Chevron down icon Chevron up icon
Chapter 5: Data Validation Chevron down icon Chevron up icon
Chapter 6: Azure Functions Chevron down icon Chevron up icon
Chapter 7: Azure Durable Functions Chevron down icon Chevron up icon
Chapter 8: Advanced Topics Chevron down icon Chevron up icon
Chapter 9: Authentication and Authorization Chevron down icon Chevron up icon
Chapter 10: Deploying to Azure Chevron down icon Chevron up icon
Chapter 11: What’s Next? Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.