title: Riverpod: Simple way to ingest REST API
body: <p>I'm currently building an app that is ingesting the WordPress REST API to display blog posts. On initial app load, I want to have it pull initial data with a method to then pull more posts via user interaction. I currently have this working, however, my implementation seems complex and there may be a cleaner way to get this working. I based my implementation on <a href="https://github.com/rrousselGit/river_pod/issues/57#issuecomment-1012366576" rel="nofollow noreferrer">this GitHub issue response</a>. Here is what my code looks like:</p>
  <p>In <code>main.dart</code>:</p>
  <pre><code>final blogRepository = FutureProvider((ref) async {
    final posts = await getPosts();
    return BlogService(posts);
        },
  );
  
  final blogProvider = StateNotifierProvider&lt;BlogService, List&lt;BlogPost&gt;&gt;((ref) =&gt; throw UnimplementedError(
      &quot;Access to a [BlogService] should be provided through a [ProviderScope].&quot;));
  </code></pre>
  <p>In <code>blogservice.dart</code>:</p>
  <pre><code>class BlogService extends StateNotifier&lt;List&lt;BlogPost&gt;&gt; {
    final List&lt;BlogPost&gt; _posts;
    BlogService(this._posts) : super(_posts);
    List&lt;BlogPost&gt; get posts =&gt; _posts;
  
    Future&lt;void&gt; morePosts(int length) async {
      Response response;
      var dio = Dio();
      response = await dio.get('https://wordpress-site.com/wp-json/wp/v2/posts/?offset=' + length.toString());
      var posts = (response.data as List);
  
      state = [...state, ...posts.map((post) =&gt; BlogPost.fromJson(post)).toList()];
    }
  }
  
  Future&lt;List&lt;BlogPost&gt;&gt; getPosts() async {
    Response response;
    var dio = Dio();
    response = await dio.get('https://wordpress-site.com/wp-json/wp/v2/posts/');
    var posts = (response.data as List);
  
    return posts.map((post) =&gt; BlogPost.fromJson(post)).toList();
  
  }
  </code></pre>
  <p>I think a better way of doing this would be to use <code>AsyncValue</code>, however, I wasn't able to find any good reference implementations consuming an API using this.</p>