Using Streams With HttpClient in .NET To Improve Performance and Memory Allocations

►► Master Web API development Best Practices: bit.ly/3TnqoFQ
►► Build great web apps in Blazor WebAssembly: bit.ly/437g87T
►► Support us on Patreon and get the source code: / codemaze
In this video, I will show you how to optimize your application when using an HttpClient by improving performance and memory usage with streams.
So, basically, I will use streams with HttpClient while sending requests and reading the content from responses. I will use streams only with GET and POST requests because the logic from the POST request can be applied to PUT and PATCH easily.
LINKS MENTIONED IN THE VIDEO
►► HttpClient Factory: • Use HttpClient Properl...
FOLLOW US ON SOCIAL MEDIA!
►► / marinko-spasojevic
►► / codemazeblog
►► / codemazeblog

Пікірлер: 11

  • @CodeMaze
    @CodeMazeАй бұрын

    Thank you all for watching and for your support. ►► If you want to master Web API development using best practices, check out our Web API book: bit.ly/3x75ZMM ►► Also, to build great full-stack apps with Blazor, check out our course: bit.ly/3Pw3Y33

  • @10Totti
    @10TottiАй бұрын

    Great tutorial. Thank you :)

  • @CodeMaze

    @CodeMaze

    Ай бұрын

    Thank you too for watching.

  • @10Totti
    @10TottiАй бұрын

    When possible, make a video on Hangfire, thanks.

  • @CodeMaze

    @CodeMaze

    Ай бұрын

    Good suggestion, thanks.

  • @Tamer_Ali
    @Tamer_AliАй бұрын

    Thanks a lot for the awesome video the channel should be called Code A-Maze-ng I hope you talk about Using Compression With HttpClient in your upcoming videos

  • @CodeMaze

    @CodeMaze

    Ай бұрын

    Great suggestion! I will see what I can do about it. Thank you for watching the video.

  • @elpe21
    @elpe21Ай бұрын

    Thanks. Although I don't understand your arguments that you don't have to keep all content in the memory and you can start working with the data faster. You still keep all the content in the memory at your breakpoints ;)

  • @CodeMaze

    @CodeMaze

    Ай бұрын

    You are most welcome. Yes, breakpoints are here just for the example sake but with the completition mode I use in this example, I return the control to the caller earlier, as soon as the response headers have been fully read. The body of the response may not be fully received at this point. So it is definitely a faster process. When using this option, we avoid the intermediate MemoryStream buffer, instead of getting the content directly from the stream exposed on the Socket. This avoids unnecessary allocations which is a goal in highly optimised situations. Another benefit in regards to performance is that we can begin working with the stream of data more quickly. In the default mode, when ResponseContentRead is used, first the content is buffered, then the method returns control to the calling method. With ResponseHeadersRead, we can begin reading the data from the stream, even while it is being sent over the network.

  • @danilok23
    @danilok23Ай бұрын

    Great tutorial. Thank you :)

  • @CodeMaze

    @CodeMaze

    Ай бұрын

    You are most welcome. Thank you for watching.