Eve and falsk at the same time. TRIAL
Runs on MongoDb db-name eve.
Run the following python apps simultaniously. E.g. in a split console screen: Screen to split terminal
Console 1: python eveapp.py
Console 2: python flasker.py
Add some data to play with:
curl -d '[{"name": "tvättmaskin", "state": "off"}]' -H 'Content-Type: application/json' http://0.0.0.0:5111/unit
"Right now only state on and off is allowed."
curl http://127.0.0.1:5000/all/on | jsonify
curl -H 'Content-Type: application/json' http://127.0.0.1:5111/unit/obama | jsonify
{
"_created": "Mon, 09 Feb 2015 13:21:16 GMT",
"_etag": "8b11ff59a484bdc74827a7c5cc7c7a33322f602c",
"_id": "54d8b44c9f19a36cc98cbdcf",
"_links": {
"collection": {
"href": "/unit",
"title": "unit"
},
"parent": {
"href": "",
"title": "home"
},
"self": {
"href": "/unit/54d8b44c9f19a36cc98cbdcf",
"title": "unit"
}
},
"_updated": "Thu, 12 Feb 2015 12:00:09 GMT",
"name": "obama",
"state": "on"
}
To patch an item (with etag-check "If-Match"-thing)
curl -H "Content-Type: application/json" -H "If-Match: df43b5315ceebb5b45ac6825cd48caeb154d787c" -X PATCH -i http://0.0.0.0:5111/unit/54d8b2639f19a36c2c337a99 -d '{"state": "nigh"}'
jsonify is aliased to python -m json.tool
{
"_id" : ObjectId("54d8b44c9f19a36cc98cbdcf"),
"_updated" : ISODate("2015-02-09T13:21:16.000Z"),
"_created" : ISODate("2015-02-09T13:21:16.000Z"),
"_allowed_fields" : {
"state" : {
"0" : "off",
"1" : "on"
}
},
"name" : "obama",
"state" : "off"
}
Check settings.py out and see the configuration of the rules for the fields in the schema definition.
- Todo-list for different areas (cabin e.g.) How to
"Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:5111/all/on. This can be fixed by moving the resource to the same domain or enabling CORS." Unleash ajax with CORS