Yupeek/django-rest-models

Follow 301 redirect from API

Opened this issue · 1 comments

I've successfully connected two django apps using django-rest-models 1.9.2, but I was facing following issue

When I've left everything in default as per tutorials (rest_framework and dynamic_rest on API server side and rest_models on client side) I was unable to run client application due to error:

django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
services.ServiceBase: (rest_models.E001) the remote api does not respond to us. OPTIONS http://localhost:8000/servicebase => 301
	HINT: check the url for the remote api or the resource_path

It's because request is lacking the trailing slash. So API server responds with 301 redirect, but rest_models fail, because it's not 200 -

if res.status_code != 200:
. Is it possible to follow redirects somehow?

To bypass this I've changed my API - passed extra parameter to router constructor in urls.py (bellow). But I'd prefer original behavior.

...
from rest_framework import routers

router = routers.DefaultRouter(trailing_slash=False)
router.register(r'servicebase', views.ServiceBaseViewSet)

urlpatterns = [
    path('', include(router.urls)),
...

Thanks!

Just a note.

According to requests docs it should follow 301 redirect automatically for GET, OPTIONS, POST, PUT, PATCH or DELETE. Only where you need to explicitly enable it is HEAD.

But I'm not sure how exactly we use requests and if we should change something under ApiVerbShortcutMixin in

class ApiVerbShortcutMixin(object):