[DN] Implement API to fetch single story
See original GitHub issueWe’re relying on a cache in StoriesRepository to get the data required to display a Designer News story:
class GetStoryUseCase @Inject constructor(private val storiesRepository: StoriesRepository) {
operator fun invoke(id: Long): Result<Story> {
val result = storiesRepository.getStory(id)
return if (result is Result.Success) {
Result.Success(result.data.toStory())
} else {
Result.Error(IllegalStateException("Story $id not cached"))
}
}
}
The cache is populated when retrieving a bundle of stories from the API StoriesRepository.loadStories(page: Int).
If the story is not present in the cache, then we’ll return an error.
This blocks #436 because it’s not possible to populate this cache from the scraped search API because we only get ID and title. The two proposed solutions in that ticket
- chain the search call onto fetching the full data for each of the stories
- (I started working on this one) introduce a new StorySearchResult PlaidItem (which only needs ID, title) and defer the fetch until opening the details
each depend on there being an API for fetching an individual story.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
[DN] Implement API to fetch single story · Issue #602 - GitHub
The cache is populated when retrieving a bundle of stories from the API StoriesRepository.loadStories(page: Int) . If the story is not present ...
Read more >How To Use the JavaScript Fetch API to Get Data - DigitalOcean
One approach to using the Fetch API is by passing fetch() the URL of the API as a parameter: fetch(url). Copy. The fetch()...
Read more >Fetch API – How to Make a GET Request and POST Request ...
To make a simple GET request with fetch, you just need to pass in the URL endpoint as an argument. To make a...
Read more >Web API implementation - Best practices for cloud applications
Learn about best practices for implementing a web API and publishing it to make it available to client applications.
Read more >An awesome guide on how to build RESTful APIs with ASP ...
Let's start handling GET requests. First of all, when someone requests data from /api/categories via GET verb, the API needs to return all...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Wait ignore me, this is for stories and not for users like I was doing 😃. That seeeeems like it should be more robust since that’s arguably the most important part of the API. The structure of that impl might still be helpful examples for this though
There be dragons here. I wrote about this a bit in a blog post (the designer news section): https://link.medium.com/shZ1GO6KDT
TL;DR - in my experience, that endpoint basically never worked most of the time. Maybe they’ve improved it though!