Django REST framework → Postman collection
Turn your DRF routers, ViewSets and serializers into a complete Postman collection, including request bodies, JWT or Token auth, filters and pagination. You don't need an OpenAPI schema, drf-spectacular or drf-yasg.
Why DRF teams use routeman
The usual route from a Django REST framework project to Postman goes through OpenAPI. You install drf-spectacular or drf-yasg, fix the warnings, annotate the views it can't understand, export the schema and import it into Postman. Then you still have to add login, tokens and environments by hand.
routeman skips all of that. It loads your URLconf the same way Django does and inspects the real view classes and serializers. You get a Postman collection that already knows how to log in.
What routeman reads from a DRF project
- Routes:
DefaultRouterandSimpleRouterregistrations, ViewSets (list, create, retrieve, update, partial_update, destroy), custom@actions (detail and list),APIViews, generic views and@api_viewfunctions, through any depth ofinclude(). - Bodies:
serializer_classandget_serializer_class(), nested serializers,many=True, relations,ChoiceField,FileField/ImageField(multipart with file pickers) and validators. Read-only fields are skipped. - Serializers built inside the view, for example
LoginSerializer(data=request.data). - Query parameters: pagination classes (page/page_size, limit/offset, cursor),
SearchFilter,OrderingFilter, django-filterfilterset_fieldsandfilterset_class. - Auth:
authentication_classesandpermission_classes(per view and fromDEFAULT_*settings): SimpleJWT,TokenAuthentication, Knox, Basic and Session.AllowAnyendpoints get No Auth.
Example
# shop/serializers.py
class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
fields = ["id", "name", "sku", "price", "status", "image"]
read_only_fields = ["id"]
# shop/views.py
class ProductViewSet(viewsets.ModelViewSet):
queryset = Product.objects.all()
serializer_class = ProductSerializer
filter_backends = [SearchFilter, OrderingFilter]
search_fields = ["name", "sku"]
ordering_fields = ["price"]
@action(detail=True, methods=["post"])
def publish(self, request, pk=None):
...
# shop/urls.py
router = DefaultRouter()
router.register("products", ProductViewSet)
urlpatterns = [
path("api/v1/", include(router.urls)),
path("api/v1/auth/token/", TokenObtainPairView.as_view()),
path("api/v1/auth/token/refresh/", TokenRefreshView.as_view()),
]
$ routeman generate
✓ django: 10 requests (4 POST, 3 GET, 1 PUT, 1 PATCH, 1 DELETE)
✓ auth: bearer (login: POST /api/v1/auth/token/)
✓ wrote postman/shop-api.postman_collection.json
✓ wrote postman/shop-api.local.postman_environment.json
done in 0.26s - import the files in Postman (File → Import)
This is real output for the code above. In Postman you get:
- An Auth folder. Token obtain pair sends
{"username": "{{username}}", "password": "{{password}}"}and its test script savesaccessandrefresh. Token refresh sends{"refresh": "{{refresh_token}}"}. Both are set to No Auth. - A Shop folder with List products, Create product, Get product, Update product, Partially update product, Delete product and the custom Publish action.
- List products has
page(fromPageNumberPagination),searchandorderingquery parameters, added but disabled. - Create product is
multipart/form-databecause of theImageField:name=John Doe,price=1.5,status=draft(a valid choice) and a file picker forimage. The read-onlyidis left out. - Collection-level Bearer auth sends
{{access_token}}to everything else, becauseDEFAULT_AUTHENTICATION_CLASSESuses SimpleJWT.
Path ids are named after the resource: /api/v1/products/{{product_id}}/, typed as UUID or integer from the model's primary key.
Step by step
- Activate the virtualenv you run
manage.pywith, thenpip install routeman. - From the folder that contains
manage.py, runrouteman generate. routeman usesDJANGO_SETTINGS_MODULEfrommanage.py, or pass-a config.settings. - Import the files from
postman/, select the environment, fillusername/passwordand send Token.
The full walkthrough, including SimpleJWT, Knox and token-auth details, is in How to generate a Postman collection from Django REST framework.
DRF questions
Does it work alongside drf-spectacular?
Yes. routeman doesn't use or conflict with drf-spectacular or drf-yasg. Keep them for Swagger UI if you like. routeman reads the views directly either way.
What about views that build a serializer themselves?
Views that call SomeSerializer(data=request.data) are understood too. If a view uses no serializer at all, routeman reads request.data.get(...) calls in the view and marks the body as inferred.
My API uses TokenAuthentication, not JWT.
That's detected. The collection sends Authorization: Token {{access_token}}, and the login request stores the token (or Knox token) from the response.