-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martijn Jacobs
committed
Dec 29, 2015
1 parent
33cb03d
commit cd56715
Showing
1 changed file
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |