In this article, I will use a demo Web API application in ASP.NET Core to show you how to transmit files through an API endpoint. In the final HTML page, end users can left-click a hyperlink to download the file or right-click the link to choose “
Save Link As” in the context menu and save the file.
The full solution can be found in my GitHub repository, which includes a web project for uploading/downloading files and an integration test project for testing controller methods.
Now let’s dive in.
In ASP.NET Core, a Web API action method usually returns an
ASP.NET Core uses configuration providers to read configuration key-value pairs from a variety of sources. You can read more about configuration in ASP.NET Core in its official documentation, which has covered tons of use cases in detail.
Recently, when I set a JSON array in the
appsettings.json files in an ASP.NET Core project, the result of the final configuration data surprised me. The array did not behave the same as other JSON objects that could be overridden in an environment-specific
appsettings.json file. Instead, the final array could have more elements than expected. After some googling, I found that there are…
Caching is a common technique to reduce the number of trips for fetching data that seldom changes. Thus we can take advantage of caching to boost our application’s performance. ASP.NET Core provides several caching libraries, including in-memory caching, distributed caching, and many others. Among these caching techniques,
IMemoryCache, the simplest cache, is included in an ASP.NET Core web project by default and works natively with dependency injection.
There are many introductory articles talking about using the
IMemoryCache to store data in the memory of the webserver. However, few of them have mentioned how to ensure the consistency of cached values…
I wrote an article entitled Upload Files with Angular and .NET Web API recently. To continue on this subject, in this article I will show you the details of creating an Angular component to upload multiple files within one HTTP request to an API endpoint. The demo app works as the following screen recording shows.
We often want to write integration tests to evaluate our app’s whole request-response pipeline. For example, we want our API endpoints to return the same responses given the same requests. These integration tests are helpful in catching cases of missing properties in the JSON responses, mismatching upper/lower cases of property names, obsolete error messages, and so on.
The ASP.NET official documentation has an article entitled Integration tests in ASP.NET Core, which covers lots of aspects of integration tests in ASP.NET Core using the xUnit test framework. However, the magical
IClassFixture<T> in xUnit creates confusion and difficulties for developers who are…
In this article, I will show you how tuples can be used to save some coding in certain scenarios. The idea is simple, but I don’t see similar code much, so I think it’s worth writing a short article to introduce it to more people.
A data transfer object (DTO) is an object that carries data between processes. In a lot of articles, DTOs are described as simple containers for data to be transferred across system boundaries. The key signature of a DTO is that it does not contain any business logic or behavior.
For example, when we query a…
In this article, we will go through details of creating an Angular component for uploading files to a .NET Web API endpoint. The following screen recording shows the demo app.
We regularly need to create some test data (or objects) for unit tests. A lot of unit tests only utilize a part of the input object and disregard the rest of the properties of the data object. For example, if a
Person object contains a name, gender, birth date (and so on) and we want to write a unit test to check the calculation of a person’s age, we know that a person’s age only depends on the current date and the person’s birth date, and the person’s other attributes do not matter in this specific unit test. …
In my last article, JWT Auth in ASP.NET Core, we talked about the implementation of JWT in the back-end. To follow up, this article will focus on the front-end part of the JWT story. You can find the front-end source code from the same GitHub repository as the back-end part.
To make JWT authentication work, the front-end application at least operates in the following scenes:
JSON Web Token (JWT) is a compact and URL-safe string, which represents claims in a specific format that is defined by the industry-standard RFC 7519. JWT is a standard method to transmit claims securely between two parties. People typically use JWTs as identity proof in web applications and mobile apps.
There are many articles talking about JWT, and I think JWT is really being hyped. As a responsible writer, I would strongly encourage you to thoroughly consider whether you should use JWT at all. The following articles are worth reading in order to make an educated and unbiased decision.