I build some blazor app
and i want to have HttpGet like
person? x = await _httpClient.Get<person?>("url");So from api if i return person then i want x to be it value, if from api i return NULL want to x be NULL
How to do this properly?
i have some httpclient with get like for example
public async Task<T> Get<T>(string uri, int timeOut = 100){ using var response = await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, uri), linkedCts.Token); return await response.Content.ReadFromJsonAsync<T>(); }}but the compilator on this response.Content.ReadFromJsonAsync<T>() says that possible null return
But still if I return NULL from api then it throwsThe input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.'
so does i need it to change to be of Task<T?> so it may return null? what is right path here?
what is best approach for this ? or am I missing something and this is not right way ?
Thank You and regards!