Skip to content

Commit

Permalink
At basket retrieval example
Browse files Browse the repository at this point in the history
  • Loading branch information
Martijn Jacobs committed Dec 30, 2015
1 parent f4c21ca commit 3f3f71a
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions docs/source/usage/communicate_with_the_api.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@
=============
Example Usage
=============
When you browse through the API (see also the ":ref:`django-oscar-sandbox`" section), most of the things are already pretty clear in terms how you can communicate with the API. In the following examples we use the python `requests`_ package to demonstate how the API works.

.. _`requests`: http://docs.python-requests.org/


Get the basket
--------------
First get our basket and see the response:

.. code-block:: python
import requests
import json
response = requests.get('http://localhost:8000/api/basket/')
print response.content
{
"currency": null,
"id": 1,
"is_tax_known": true,
"lines": "http://localhost:8000/api/baskets/1/lines/",
"offer_discounts": [],
"owner": null,
"status": "Open",
"total_excl_tax": "0.00",
"total_excl_tax_excl_discounts": "0.00",
"total_incl_tax": "0.00",
"total_incl_tax_excl_discounts": "0.00",
"total_tax": "0.00",
"url": "http://localhost:8000/api/baskets/1/",
"voucher_discounts": []
}
Note that we are not logged, so we need to send the cookies (wich include the `django session id`) to make sure we get the same basket again. See also the ":ref:`header-session-label`" for an alternative option.

.. code-block:: python
response = requests.get('http://localhost:8000/api/basket/', cookies=response.cookies)
print loads(response.content)['id']
1
.. attention::
Use the python requests module to show some of the examples here

0 comments on commit 3f3f71a

Please sign in to comment.