REST API¶
Der Shop stellt eine REST-API über django-oscar-api bereit.
Übersicht¶
Die API ist unter /api/ erreichbar und verwendet das Django REST Framework.
/api/
├── /products/ # Produkte + Varianten
├── /basket/ # Warenkorb-Operationen
├── /orders/ # Bestellungen (Authentifiziert)
├── /checkout/ # Bestellabschluss
├── /addresses/ # Kundenadressen
├── /partners/ # Lieferanten
└── /login/ # Authentifizierung
Authentifizierung¶
Die API verwendet Token-basierte Authentifizierung:
Authorization: Token <api_token>
Tokens werden im Django-Admin oder Dashboard vergeben.
Wichtige Endpunkte¶
Produkte¶
GET /api/products/
GET /api/products/{id}/
GET /api/products/?category=Getränke
Antwort enthält:
- id, title, description
- price, currency
- images (URLs)
- categories
- availability
- attributes (Produkttyp-spezifisch)
- is_deposit (Pfand)
Warenkorb¶
GET /api/basket/ # Warenkorb-Inhalt
POST /api/basket/add-product/ # Produkt hinzufügen
POST /api/basket/remove-line/ # Position entfernen
POST /api/basket/set-quantity/ # Menge ändern
Checkout¶
POST /api/checkout/
Body:
{
"shipping_address_id": 42,
"billing_address_id": 42,
"shipping_method_code": "standard",
"payment_method": "paypal",
"time_slot_id": "123",
"floor_number": 0
}
Bestellungen¶
GET /api/orders/ # Eigene Bestellungen
GET /api/orders/{number}/ # Bestellungsdetail
Swagger-Dokumentation¶
Die interaktive API-Dokumentation ist unter /api/swagger/ erreichbar.
Dateien¶
| Datei | Funktion |
|---|---|
api/urls.py |
URL-Routing der API |
oscarapi/ |
django-oscar-api Endpunkte |
Konfiguration¶
# config/settings/api.py
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework.authentication.TokenAuthentication",
],
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": 20,
}