From b5616789cc947fa74540cddab9644ea20c46184c Mon Sep 17 00:00:00 2001 From: seba Date: Fri, 7 Oct 2011 00:48:22 +0200 Subject: [PATCH] Doc: Added examples --- k4ever/docs/django/api.rst | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/k4ever/docs/django/api.rst b/k4ever/docs/django/api.rst index ed8c49e..07a81f1 100644 --- a/k4ever/docs/django/api.rst +++ b/k4ever/docs/django/api.rst @@ -169,6 +169,36 @@ Decorators Examples -------- - - how to use the api - - examples with... wget.. python-rest? +Here are some code examples how to use the API with different clients or languages. +In these examples we have for authentication *frundy*/*foobar* as a normal user and *testplugin*/*maunz* as a plugin. + +WGET +"""" +``wget`` comes in handy at this task. At some point it might be that ``wget`` cannot provide full access to the API cause it is unable to send ``PUT`` and ``DELETE`` requests. For debugging purposes the flags `-Sd` are recommended. + +.. code-block:: bash + + # find item with barcode + wget -qS -O- --auth-no-challenge --http-user=frundy --http-password=foobar http://server/api/buyable/item/?barcode=4029764001807 + # buy 10 times item with id 3 + wget -qS -O- --auth-no-challenge --http-user=frundy --http-password=foobar http://server/api/buyable/item/3/ --post-data "amount=10" + # as plugin get users account balance + wget -qS -O- --auth-no-challenge --http-user=testplugin --http-password=maunz http://server/api/buyable/account/balance/?user=frundy + # as plugin buy 10 times item with id 3 + wget -qS -O- --auth-no-challenge --http-user=testplugin --http-password=maunz http://server/api/buyable/item/3/ --post-data "amount=10&user=frundy + +CURL +"""" +As one might see, ``curl`` is quite nice for accessing the API. ``curl`` also supports the ``HTTP``, ``PUT`` and ``DELETE`` methods. + +.. code-block:: bash + + # find item with barcode + curl --basic http://frundy:foobar@server/api/buyable/item/?barcode=4029764001807 + # buy 10 times item with id 3 + curl --basic -X POST --data "amount=10" http://fruny:foobar@server/api/buyable/item/3/ + # as plugin get users account balance + curl --basic http://testplugin:maunz@server/api/buyable/account/balance/?user=frundy + # as plugin buy 10 times item with id 3 + curl --basic -X POST --data "amount=10" http://testplugin:maunz@server/api/buyable/item/3/?user=frundy