When you retrieve a discussion via the API, you only get 20 full posts but you also get the IDs for the entire post stream in the posts
relationship.
When you scroll in the stream you can retrieve the full content of the other posts with GET /api/posts?filter[id]=<post ID 1>,<post ID 2>,<post ID 3>,<etc>
By default Flarum fetches posts by groups of 20, but you should be able to request up to 50 at the same time without having to modify Flarum's backend.
If you want to jump to a specific post by number inside of an already open discussion, you can use GET /api/posts?filter[discussion]=<discussion id>&page[near]=<post number>
which will return 10 post prior and 10 posts after the target post number.
You can also use page[near]=<post number>
on the GET /api/discussions/<id>
endpoint if you want to open a new discussion at a specific place.
This is how the single page application uses the API.