flask_peeweeのRestAPIで取得条件を設定する
flask_peeweeのRestAPIではクエリパラメータで取得条件を設定することができます
全件取得
http://localhost:5000/api/post/
{ "meta": { "model": "post", "next": "", "page": 1, "previous": "" }, "objects": [ { "entry": "test_entry1", "created": "2011-11-15 17:23:57", "user_id": 1, "id": 1, "title": "test_title1" }, { "entry": "test_entry2", "created": "2011-11-15 17:24:06", "user_id": 2, "id": 2, "title": "test_title2" } ] }
ユーザーの条件を設定
http://localhost:5000/api/post?user=2
{ "meta": { "model": "post", "next": "", "page": 1, "previous": "" }, "objects": [ { "entry": "test_entry2", "created": "2011-11-15 17:24:06", "user_id": 2, "id": 2, "title": "test_title2" } ] }
djangoのようにリレーションをまたいだ取得条件を設定することもできます
http://localhost:5000/api/user/
{ "meta": { "model": "user", "next": "", "page": 1, "previous": "" }, "objects": [ { "username": "admin", "created": "2011-11-15 17:23:10", "admin": true, "email": "", "active": true, "id": 1 }, { "username": "guest", "created": "2011-11-15 17:23:30", "admin": false, "email": "", "active": true, "id": 2 } ] }
http://localhost:5000/api/post?user__username=guest
{ "meta": { "model": "post", "next": "", "page": 1, "previous": "" }, "objects": [ { "entry": "test_entry2", "created": "2011-11-15 17:24:06", "user_id": 2, "id": 2, "title": "test_title2" } ] }