I'm interested in creating a dynamic page that continuously fetches data from the backend, allowing the data set to grow over time until the backend indicates completion (which may never happen). Similar to the concept discussed in this article, but utilizing a backend based on .NET Core.
Initially, the Angular service would appear as follows.
@Injectable()
export class TheService {
constructor(private httpClient: HttpClient) {}
getStuff(): Observable<Thing[]> {
return this.httpClient.get<Thing[]>('http://localhost:3000/stuff');
}
getThing(): Observable<Thing> {
return this.httpClient.get<Thing>('http://localhost:3000/thing');
}
}
The challenge lies on the backend side. When returning a collection of things, the operation is completed with Ok()
indicating a successful status code of 200. However, I aim to return one thing at a time (or an array of things without completing the final data set). Essentially, I want to emit values from the .NET API without closing the connection. As a simplification, using responses of type String
instead of Thing
is acceptable.
Is this achievable using common practices in .NET? I'm referring to the default GET method as shown below.
[HttpGet("stuff")]
public ActionResult<IEnumerable<Thing>> GetThing()
{
IEnumerable<Thing> output = ...;
return Ok(output);
}
[HttpGet("thing")]
public ActionResult<Thing> GetThing()
{
Thing output = ...;
return Ok(output);
}
After researching extensively, I have not come across relevant information. While there are numerous resources on the Angular side, focusing on observables, RxJs, etc., most examples of integrating .NET and Angular involve a serve-and-finalize connection. The best example I found, linked at the beginning, does not involve .NET on the backend. I suspect that the solution may be simpler than expected, or possibly challenging to implement.