From af13f6fd659fb87419462fc439e594afe6790873 Mon Sep 17 00:00:00 2001 From: Marijn Besseling Date: Sun, 19 Oct 2025 21:55:30 +0200 Subject: add number & boolean formatting, replace httpclientfactory with httpclient with base url, add requset message to brp page --- Blog/Services/BrpService.cs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'Blog/Services') diff --git a/Blog/Services/BrpService.cs b/Blog/Services/BrpService.cs index e2e23c0..c3eed5a 100644 --- a/Blog/Services/BrpService.cs +++ b/Blog/Services/BrpService.cs @@ -4,7 +4,7 @@ using Microsoft.Extensions.Caching.Hybrid; namespace Blog.Services; -public class BrpService(HybridCache cache, IHttpClientFactory httpClientFactory) +public class BrpService(HybridCache cache, HttpClient client) { public async Task GetBrpEntriesAsync(CancellationToken cancellationToken = default) { @@ -21,7 +21,7 @@ public class BrpService(HybridCache cache, IHttpClientFactory httpClientFactory) .ConfigureAwait(false); } - public async Task GetBrpEntryAsync(string bsn, CancellationToken cancellationToken = default) + public async Task<(JsonDocument request, JsonDocument response)> GetBrpEntryAsync(string bsn, CancellationToken cancellationToken = default) { return await cache.GetOrCreateAsync( $"brp/{bsn}", @@ -31,21 +31,20 @@ public class BrpService(HybridCache cache, IHttpClientFactory httpClientFactory) .ConfigureAwait(false); } - private async Task FetchBrpEntryAsync(string bsn, CancellationToken cancellationToken) + private async Task<(JsonDocument request, JsonDocument response)> FetchBrpEntryAsync(string bsn, CancellationToken cancellationToken) { - var client = httpClientFactory.CreateClient("brp"); var response = await client.PostAsJsonAsync( - "https://brp.bes.is/haalcentraal/api/brp/personen", - new - { - type = "RaadpleegMetBurgerservicenummer", - burgerservicenummer = new[] { bsn }, - fields = new[] {"aNummer","adressering","burgerservicenummer","datumEersteInschrijvingGBA","datumInschrijvingInGemeente","europeesKiesrecht","geboorte","gemeenteVanInschrijving","geslacht","gezag","immigratie","indicatieCurateleRegister","kinderen","leeftijd","naam","nationaliteiten","ouders","overlijden","partners","uitsluitingKiesrecht","verblijfplaats","verblijfstitel","verblijfplaatsBinnenland","adresseringBinnenland"}, - }, + "haalcentraal/api/brp/personen", + new RaadpleegMetBurgerservicenummer(bsn), cancellationToken) .ConfigureAwait(false); await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); - return await JsonDocument.ParseAsync(stream, cancellationToken: cancellationToken).ConfigureAwait(false); + var responseDocument = await JsonDocument.ParseAsync(stream, cancellationToken: cancellationToken).ConfigureAwait(false); + + await using var requestStream = await response.RequestMessage!.Content!.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); + var requestDocument = await JsonDocument.ParseAsync(requestStream, cancellationToken: cancellationToken).ConfigureAwait(false); + + return (requestDocument, responseDocument); } } \ No newline at end of file -- cgit v1.2.3