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
€18.99 per month
Paperback 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
€18.99 per month
Paperback 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 a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781835468852
Vendor :
Microsoft
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Nov 22, 2024
Length: 166 pages
Edition : 1st
Language : English
ISBN-13 : 9781835468852
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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.