1e03034dd3
* Replaced stub.txt with the samples from git@github.com:logiclrd/ASPNetCoreStreamingExample.git. * Reformatted to match .editorconfig. * Added an exclusion for Properties folder in .gitignore, since this is where launchSettings.json lives. Added launchSettings.json files. * Added root menus to AsynchronousWithSystemTextJson and SynchronousWithNewtonsoftJson. Updated launchSettings.json in each project correspondingly. Updated Startup.cs to output instructions for the user, since it appears `dotnet run` doesn't actually start a browser. * Added sample DynamicBinaryStream. * Added RootNamespace properties to AsynchronousWithSystemTextJson.csproj and SynchronousWithNewtonsoftJson.csproj. * Corrected folder structure. Removed LICENSE file imported from external repository. * Added comment explaining why we create a separate JsonTextWriter for each line in SongLyricsMiddleware.cs. * Removed unnecessary .gitignore files. * Apparently, Visual Studio was still doing implicit using statements even though it was turned off in the project file. Now it's not doing them, so this commit adds the using statements that were implicit. * Converted projects to use so-called "minimal hosting" with all initialization inside Program.cs instead of using a Startup class. * Updated Microsoft.AspNetCore.Mvc.NewtonsoftJson reference to the latest 7.0.0 prerelease version. * Delete .gitignore * Enabled implicit usings in all projects. Removed unnecessary using statements. Converted all C# source files to file-scoped namespaces. Corrected cases where namespaces including the solution file name (not committed to the repository) were accidentally used. Enabled Nullable annotation in SynchronousWithNewtonsoftJson.csproj. * Lumped all using statements into single blocks. Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> |
||
---|---|---|
.. | ||
AsynchronousWithSystemTextJson | ||
DynamicBinaryStream | ||
SynchronousWithNewtonsoftJson | ||
.editorconfig | ||
README.md |
README.md
ASP.NET Core Streaming Example
This repository contains sample code for the article "Streaming Responses in ASP.NET Core" in the ASP.NET Core documentation.
What
The project contains two implementations of the definition of a simple ASP.NET Core web site that contains endpoints that sing a song:
AsynchronousWithSystemTextJson
SynchronousWithNewtonsoftJson
These endpoints sing the song indefinitely, streaming the song repeatedly until the client disconnects. This acts as a demonstration of how to implement streaming endpoints with ASP.NET Core.
Compiling
This project can be compiled in Visual Studio, or with the dotnet
command-line tool:
dotnet build
Running
Within Visual Studio, this project will by default run using IIS Express. This can be changed to self-host with Kestrel.
The project can also be launched with the dotnet
command-line tool, which self-hosts with Kestrel:
dotnet run
Using
There are two examples that show alternative implementations. With an example server running, you can use a browser window or command-line tools to inspect output from the hosted endpoints. Simply append the desired endpoint onto the base URI displayed in the console where the server is running.
- Browser: Simply browse to the URL. Some browsers may spool up some of the response before they begin displaying it in realtime.
- PowerShell: There is no built-in function in PowerShell that can display a web response in realtime.
- Curl:
curl URL --no-buffer
- NB: Windows 10 ships with a native port of
curl.exe
-- specify the extension if calling from PowerShell, since PowerShell by default aliasescurl
toInvoke-WebRequest
.
- NB: Windows 10 ships with a native port of
- Wget:
wget -qO- URL
AsynchronousWithSystemTextJson
When running, this project presents a web server with a single endpoint.
- Controller endpoint:
/v1/sing
This project hosts itself on port 5100. A sample URL is:
SynchronousWithNewtonsoftJson
When running, this project presents a web server with two endpoints. These endpoints have identical behaviour, but one is implemented using an ASP.NET Core Controller and the other using ASP.NET Core Middleware.
- Controller Endpoint:
/v1/sing
- Middleware Endpoint:
/middleware/sing
This project hosts itself on port 5000. Sample URLs are: