"""Simple JSON API application with in-memory storage."""

import asyncio
import logging
from collections import defaultdict, OrderedDict

import time
from aiohttp import web

from aiohttp_json_api import setup_jsonapi
from aiohttp_json_api.const import JSONAPI


def setup_fixtures(app):
    from examples.simple.models import Article, People, Comment

    registry = app[JSONAPI]['registry']

    people = tuple(sorted(People.populate(), key=lambda p: p.id))
    comments = tuple(sorted(Comment.populate(people), key=lambda c: c.id))
    articles = tuple(sorted(Article.populate(comments, people),
                            key=lambda a: a.id))

    for entities in (people, comments, articles):
        for entity in entities:
            # ResourceID for entity
            resource_id = registry.ensure_identifier(entity)
            app['storage'][entity.__class__][resource_id] = entity

    return app


async def init() -> web.Application:
    from examples.simple.schemas import (
        ArticleSchema, CommentSchema, PeopleSchema
    )

    app = web.Application(debug=True)
    app['storage'] = defaultdict(OrderedDict)

    setup_jsonapi(app, (ArticleSchema, CommentSchema, PeopleSchema),
                  meta={'example': {'version': '0.0.1'}})
    # After JSON API application setup fixtures able to use Registry if needed.
    # In setup_fixtures function, Registry will be used to setup IDs
    # of saved entities.
    setup_fixtures(app)

    return app


def main():
    loop = asyncio.get_event_loop()

    root = logging.getLogger()
    if root.handlers:
        for handler in root.handlers:
            root.removeHandler(handler)

    logging.basicConfig(
        level=logging.DEBUG,
        format='%(levelname)-8s [%(asctime)s.%(msecs)03d] '
               '(%(name)s): %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S'
    )
    logging.Formatter.converter = time.gmtime

    app = loop.run_until_complete(init())
    web.run_app(app,
                access_log_format='%a (%{X-Real-IP}i) %t "%r" %s %b %Tf '
                                  '"%{Referrer}i" "%{User-Agent}i"')


if __name__ == '__main__':
    main()

@@ -24,16 +24,24 @@
 ication 
+example 
 with in-
@@ -659,22 +659,23 @@
     for 
-entiti
+resourc
 es in (p
@@ -718,24 +718,27 @@
 for 
-entity in entiti
+resource in resourc
 es:%0A
@@ -757,27 +757,109 @@
 # Re
-sourceID for entity
+gistry have a helper to return a ResourceID of instances%0A            # of registered resource classes
 %0A   
@@ -908,22 +908,24 @@
 ntifier(
-entity
+resource
 )%0A      
@@ -945,22 +945,24 @@
 orage'%5D%5B
-entity
+resource
 .__class
@@ -984,14 +984,16 @@
 %5D = 
-entity
+resource
 %0A%0A  
@@ -1229,16 +1229,435 @@
 dDict)%0A%0A
+    # Note that we pass schema classes, not instances of them.%0A    # Schemas instances will be initialized application-wide.%0A    # Schema instance is stateless, therefore any request state must be passed%0A    # to each of Schema's method as RequestContext instance.%0A    # RequestContext instance created automatically in JSON API middleware%0A    # for each request. JSON API handlers use it in calls of Schema's methods.%0A
     setu
@@ -1775,16 +1775,17 @@
 0.1'%7D%7D)%0A
+%0A
     # Af
@@ -1788,16 +1788,25 @@
 # After 
+setup of 
 JSON API
@@ -1818,22 +1818,16 @@
 ication 
-setup 
 fixtures
@@ -1847,16 +1847,22 @@
 Registry
+%0A    #
  if need
@@ -1864,22 +1864,16 @@
  needed.
-%0A    #
  In setu
@@ -1918,45 +1918,77 @@
 used
+%0A    #
  to 
-setup IDs%0A    # of saved entities
+get ResourceID as keys of resources saved to simple storage
 .%0A  
@@ -2499,52 +2499,55 @@
 ())%0A
-    web.run_app(app,%0A                access_
+%0A    # More useful log format than default%0A    
 log_
@@ -2552,17 +2552,19 @@
 g_format
-=
+ = 
 '%25a (%25%7BX
@@ -2594,34 +2594,19 @@
 %25b %25Tf '
-%0A                 
+ %5C%0A
         
@@ -2647,16 +2647,66 @@
 gent%7Di%22'
+%0A    web.run_app(app, access_log_format=log_format
 )%0A%0A%0Aif _

Add comments in main.py of simple example