You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Whilst following your guide video I couldn't see what ApiBroker did beyond providing some sort of wrapper around a HttpClient instance. My initial thoughts were ... could he not just use HttpClient directly?
That got me thinking, most API's (like mine) are built to a standard like OData so some common extensions might be all that's needed, or did I miss something?
I would do something like this ...
publicstaticclassHttpClientExtensions{ILoggerlog;staticHttpClientExtensions(ILoggerlog)=>this.log =log;publicstaticasyncTask<Token>Authenticate(thisHttpClientclient,stringuser,stringpass){try{varauth=new{ User = user, Pass = pass };varpayload=new StringContent(auth.ToJsonForOdata(), Encoding.UTF8,"application/json");varresponse=await client.PostAsync("Account/Login", payload);
response.EnsureSuccessStatusCode();vartoken=await response.Content.ReadAsAsync<Token>();
client.DefaultRequestHeaders.Authorization =new AuthenticationHeaderValue("bearer", token.Id);returntoken;}catch{/* if we get here the server returned a json repsonse but it wasn't a token, it was more than likely an auth failure. */}
log.Warn("Auth request Failed for user "+user);returnnull;}publicstaticTask<ODataCollection<T>>GetODataCollection(thisHttpClientclient,stringquery)=> client.GetAsync(query).ContinueWith(async t =>await t.Result.Content.ReadAsAsync<ODataCollection<T>>()).Unwrap();}
Unless there's some function beyond this wrapper function for Brokers you could remove that layer altogether.
I did then noticed that you built a "LoggingBroker", would inject as a dependency an Ilogger instance through the usual mechanisms and if need be build my own ILogger structure that uses a http client within it as logging is something that happens literally everywhere in an application.
The text was updated successfully, but these errors were encountered:
hassanhabib
changed the title
Some thoughts from watching https://www.youtube.com/watch?v=5Htj8JFglb4
CODE RUB: Some thoughts from watching https://www.youtube.com/watch?v=5Htj8JFglb4
Oct 24, 2021
Interesting Hassan.
Whilst following your guide video I couldn't see what ApiBroker did beyond providing some sort of wrapper around a HttpClient instance. My initial thoughts were ... could he not just use HttpClient directly?
That got me thinking, most API's (like mine) are built to a standard like OData so some common extensions might be all that's needed, or did I miss something?
I would do something like this ...
Then in my "broker consuming" code ...
Unless there's some function beyond this wrapper function for Brokers you could remove that layer altogether.
I did then noticed that you built a "LoggingBroker", would inject as a dependency an Ilogger instance through the usual mechanisms and if need be build my own ILogger structure that uses a http client within it as logging is something that happens literally everywhere in an application.
The text was updated successfully, but these errors were encountered: