question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[DN] Implement API to fetch single story

See original GitHub issue

We’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:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ZacSweerscommented, Jan 20, 2019

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

1reaction
ZacSweerscommented, Jan 20, 2019

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found