summaryrefslogtreecommitdiff
path: root/Blog/Services/BrpService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Blog/Services/BrpService.cs')
-rw-r--r--Blog/Services/BrpService.cs23
1 files changed, 11 insertions, 12 deletions
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;
4 4
5namespace Blog.Services; 5namespace Blog.Services;
6 6
7public class BrpService(HybridCache cache, IHttpClientFactory httpClientFactory) 7public class BrpService(HybridCache cache, HttpClient client)
8{ 8{
9 public async Task<BRPEntry[]> GetBrpEntriesAsync(CancellationToken cancellationToken = default) 9 public async Task<BRPEntry[]> GetBrpEntriesAsync(CancellationToken cancellationToken = default)
10 { 10 {
@@ -21,7 +21,7 @@ public class BrpService(HybridCache cache, IHttpClientFactory httpClientFactory)
21 .ConfigureAwait(false); 21 .ConfigureAwait(false);
22 } 22 }
23 23
24 public async Task<JsonDocument> GetBrpEntryAsync(string bsn, CancellationToken cancellationToken = default) 24 public async Task<(JsonDocument request, JsonDocument response)> GetBrpEntryAsync(string bsn, CancellationToken cancellationToken = default)
25 { 25 {
26 return await cache.GetOrCreateAsync( 26 return await cache.GetOrCreateAsync(
27 $"brp/{bsn}", 27 $"brp/{bsn}",
@@ -31,21 +31,20 @@ public class BrpService(HybridCache cache, IHttpClientFactory httpClientFactory)
31 .ConfigureAwait(false); 31 .ConfigureAwait(false);
32 } 32 }
33 33
34 private async Task<JsonDocument> FetchBrpEntryAsync(string bsn, CancellationToken cancellationToken) 34 private async Task<(JsonDocument request, JsonDocument response)> FetchBrpEntryAsync(string bsn, CancellationToken cancellationToken)
35 { 35 {
36 var client = httpClientFactory.CreateClient("brp");
37 var response = await client.PostAsJsonAsync( 36 var response = await client.PostAsJsonAsync(
38 "https://brp.bes.is/haalcentraal/api/brp/personen", 37 "haalcentraal/api/brp/personen",
39 new 38 new RaadpleegMetBurgerservicenummer(bsn),
40 {
41 type = "RaadpleegMetBurgerservicenummer",
42 burgerservicenummer = new[] { bsn },
43 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"},
44 },
45 cancellationToken) 39 cancellationToken)
46 .ConfigureAwait(false); 40 .ConfigureAwait(false);
47 41
48 await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); 42 await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
49 return await JsonDocument.ParseAsync(stream, cancellationToken: cancellationToken).ConfigureAwait(false); 43 var responseDocument = await JsonDocument.ParseAsync(stream, cancellationToken: cancellationToken).ConfigureAwait(false);
44
45 await using var requestStream = await response.RequestMessage!.Content!.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
46 var requestDocument = await JsonDocument.ParseAsync(requestStream, cancellationToken: cancellationToken).ConfigureAwait(false);
47
48 return (requestDocument, responseDocument);
50 } 49 }
51} \ No newline at end of file 50} \ No newline at end of file