
Build Domain-driven HTTP services
You're building ASP .NET web APIs that need to communicate with external APIs. The UserRegister API needs to insert a new user into the database, but also talk to three different services: FileStoreService - uploads the user's profile photo PDFService - generates a new document for the user to sign EmailService - sends PDF as an email attachment. You need to register an HTTP client for each external service you want to connect to from your service. A common approach is to use the HTTPClientFactory and the named clients as follows: Add clients to the appsettings.json { "FileStorageServiceUri" : "https//file-storage-service:1234" , "PDFServiceURI" : "https//pdf-service:4567" , "EmailServiceUri" : "https//email-service:8883" } Register each (named) HTTP client in Program.cs var builder = WebApplication . CreateBuilder ( args ); builder . Services . AddHttpClient ( "FileStorage" , c => { c . BaseAddress = new Uri ( builder . Configuration [ "FileStorageUri" ]); c . DefaultRequestHeaders .
Continue reading on Dev.to Webdev
Opens in a new tab



