Builds REST APIs with Django REST Framework: models, serializers, viewsets, routers, permissions, and browsable API testing.
Agentic Workflow: Read -> Reason -> Act (api-rest-drf)
You are Api Rest Drf (backend) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — backend context for api-rest-drf
- Domain: Builds REST APIs with Django REST Framework: models, serializers, viewsets, routers, permissions, and browsable API testing.
- drf-setup: Scaffold a Django project with DRF —
pip install django djangorestframework
- viewsets: Expose CRUD via viewsets and routers —
curl -s http://localhost:8000/api/users/ | jq 'length'
- Check
knowledge and prerequisites: node.js, python, express, fastapi
2. Reason — think for api-rest-drf
- For
drf-setup: Scaffold a Django project with DRF — decide which checks to run
- For
viewsets: Expose CRUD via viewsets and routers — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-rest-drf tools
- Tools:
Glob, Grep, Read, Bash, Django-admin (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-rest-drf:737dd577
API REST v4 - Django REST Framework
REST APIs with DRF.
What This Skill Does
- Exposes models as REST resources with viewsets
- Validates and serializes with serializers
- Handles auth with permission classes
When to Use
- Python/Django teams
- Rapid CRUD APIs with admin UIs
- Standardized DRF projects
Real Commands
pip install django djangorestframework
django-admin startproject config .
python manage.py startapp api
python manage.py migrate
python manage.py runserver
ViewSet Example
from rest_framework import viewsets
from .models import User
from .serializers import UserSerializer
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
Testing
- Verify browsable API at /api/users/
- Test validation and permissions with APIClient
- Confirm 401/403 for anonymous writes
Best Practices
- Use routers to wire URLs consistently
- Add filtering and ordering mixins
- Document with drf-spectacular OpenAPI generation
Capabilities
drf-setup
Scaffold a Django project with DRF
Parameters:
app (string): Django app name
model (string): Model to expose via the API
serializer (string): DRF serializer class
Commands:
pip install django djangorestframework
django-admin startproject config .
python manage.py startapp api
python manage.py migrate
python manage.py runserver
Examples:
- django-admin startproject scaffolds the project
- python manage.py migrate applies schema
- python manage.py runserver serves the browsable API
viewsets
Expose CRUD via viewsets and routers
Commands:
curl -s http://localhost:8000/api/users/ | jq 'length'
curl -s -X POST http://localhost:8000/api/users/ -H 'Content-Type: application/json' -d '{"name":"alice","email":"a@localhost"}' -w '\n%{http_code}\n'
curl -s -o /dev/null -w '%{http_code}\n' -X POST http://localhost:8000/api/users/ -H 'Content-Type: application/json' -d '{"name":"x"}'
python manage.py test api -v 2
Examples:
References
1---2name: "api-rest-drf"3description: "Builds REST APIs with Django REST Framework: models, serializers, viewsets, routers, permissions, and browsable API testing. Use when working with drf setup, viewsets or when the user mentions drf setup, viewsets."4license: "MIT"5compatibility: "Requires node.js, python, express, fastapi, fastify, openapi. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-rest-drf8 author: Kdesk9 version: 2.0.010 category: backend11allowed-tools: "Glob Grep Read Bash(curl:*) Bash(django-admin:*) Bash(pip:*) Bash(python:*)"12---1314Builds REST APIs with Django REST Framework: models, serializers, viewsets, routers, permissions, and browsable API testing.1516## Agentic Workflow: Read -> Reason -> Act (api-rest-drf)1718You are **Api Rest Drf** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — backend context for `api-rest-drf`21- Domain: Builds REST APIs with Django REST Framework: models, serializers, viewsets, routers, permissions, and browsable API testing.22- **drf-setup**: Scaffold a Django project with DRF — `pip install django djangorestframework`23- **viewsets**: Expose CRUD via viewsets and routers — `curl -s http://localhost:8000/api/users/ | jq 'length'`24- Check `knowledge` and `prerequisites: node.js, python, express, fastapi`2526### 2. Reason — think for `api-rest-drf`27- For `drf-setup`: Scaffold a Django project with DRF — decide which checks to run28- For `viewsets`: Expose CRUD via viewsets and routers — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `api-rest-drf` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Django-admin` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `api-rest-drf:737dd577`3536# API REST v4 - Django REST Framework3738REST APIs with DRF.3940## What This Skill Does41- Exposes models as REST resources with viewsets42- Validates and serializes with serializers43- Handles auth with permission classes4445## When to Use46- Python/Django teams47- Rapid CRUD APIs with admin UIs48- Standardized DRF projects4950## Real Commands5152```bash53pip install django djangorestframework54django-admin startproject config .55python manage.py startapp api56python manage.py migrate57python manage.py runserver58```5960## ViewSet Example6162```python63from rest_framework import viewsets64from .models import User65from .serializers import UserSerializer6667class UserViewSet(viewsets.ModelViewSet):68 queryset = User.objects.all()69 serializer_class = UserSerializer70```7172## Testing73- Verify browsable API at /api/users/74- Test validation and permissions with APIClient75- Confirm 401/403 for anonymous writes7677## Best Practices78- Use routers to wire URLs consistently79- Add filtering and ordering mixins80- Document with drf-spectacular OpenAPI generation8182## Capabilities8384### drf-setup85Scaffold a Django project with DRF8687**Parameters:**88- `app` (string): Django app name89- `model` (string): Model to expose via the API90- `serializer` (string): DRF serializer class9192**Commands:**93- `pip install django djangorestframework`94- `django-admin startproject config .`95- `python manage.py startapp api`96- `python manage.py migrate`97- `python manage.py runserver`9899**Examples:**100- django-admin startproject scaffolds the project101- python manage.py migrate applies schema102- python manage.py runserver serves the browsable API103104### viewsets105Expose CRUD via viewsets and routers106107**Commands:**108- `curl -s http://localhost:8000/api/users/ | jq 'length'`109- `curl -s -X POST http://localhost:8000/api/users/ -H 'Content-Type: application/json' -d '{"name":"alice","email":"a@localhost"}' -w '\n%{http_code}\n'`110- `curl -s -o /dev/null -w '%{http_code}\n' -X POST http://localhost:8000/api/users/ -H 'Content-Type: application/json' -d '{"name":"x"}'`111- `python manage.py test api -v 2`112113**Examples:**114- -cli --help115- -api --help116117## References118- [DRF Quickstart](https://www.django-rest-framework.org/tutorial/quickstart/)119- [DRF Viewsets](https://www.django-rest-framework.org/api-guide/viewsets/)