Simulating Request Delay With RxJS

Ole Ersoy
Jan 5, 2019


Photo by insung yoon on Unsplash


We are requesting post data of type Post and we wish to simulate the retrieval of a single Post instance.


Lets first create the Post type:

type Post = { title: string, content: string };

Next use the RxJS delay operator to simulate the delay in retrieving the Post instance like this:

const post:Observable<Post> = of( 
{title: 'Simulating HTTP Requests',
content: 'This is off the hook!!'})

The Post instance is logged after the 2 second delay introduced by delay(2000) .