Commit ef3fd8cc authored by Cédric Bonhomme's avatar Cédric Bonhomme

The user can now send requests based on any keys of the epcis event.

parent 1cbf3ba5
......@@ -20,6 +20,10 @@ installed in a Python virtual environment (with [virtualenv](http://www.virtuale
USAGE
-----
Insert a new EPCIS event:
$ curl -X PUT -d @epcis.xml http://127.0.0.1:5000/epcis.json/ --header "Content-Type:application/xml"
Get the list of the 10 last EPCIS events:
$ GET http://127.0.0.1:5000/epcis.json
......@@ -28,10 +32,10 @@ Get the list of all EPCIS events involving the electronic product code (EPC) giv
$ GET http://127.0.0.1:5000/what/urn:epc:id:sgtin:0614141.100734.400.3
Insert a new EPCIS event:
$ curl -X PUT -d @epcis.xml http://127.0.0.1:5000/epcis.json/ --header "Content-Type:application/xml"
Get the list of all EPCIS events based on your request:
$ http://127.0.0.1:5000/query/?query=ObjectEvent__bizStep&value=urn:epcglobal:epcis:bizstep:fmcg:shipped
$ http://127.0.0.1:5000/query/?query=ObjectEvent__disposition&value=urn:epcglobal:epcis:disp:fmcg:unknown
Reference
---------
......
......@@ -37,6 +37,18 @@ def where(location=None):
epcis_events = [epcis_event.data for epcis_event in result]
return jsonify(result="ok", nb_items=result.count(), epcis_events=epcis_events)
@app.route('/query/', methods=['GET'])
def query():
"""
Return all EPCIS events at 'bizLocation'.
"""
query_string, value = request.args.get('query'), request.args.get('value')
result = models.EPCISEvent.objects(**{"data__"+query_string: value}).only("data")
if result.count() == 0:
return jsonify(result="no epcis event", nb_items=result.count())
epcis_events = [epcis_event.data for epcis_event in result]
return jsonify(result="ok", nb_items=result.count(), epcis_events=epcis_events)
@app.errorhandler(404)
def not_found(error=None):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment