Split API URLs to second project/settings/wsgi ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Split API URLs to second project/settings/wsgi ?

guettli-3
In one small project all web requests were done by humans in the past.

We used a login form and cookie bases sessions.

Now an API gets created and automated processes access these new URLs.

These processes use a different auth backend.

Now I see two possible solutions:


Solution1: Use one project (one settings file, one wsgi endpoint). This means we need to support several auth backends in one settings file.


Solution2: Split human and API calls. This means overhead in the configuration, but has the advantage that you can influence things like
the wsgi-worker queue better. Example: If there are several thousand API requests, the requests for humans don't suffer.


I know that there is not single truth and both solutions have their advantages and disadvantages. But maybe it helps if you write what you
think and what you learned in the past.

Regards,
  Thomas Güttler


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0d145a53-cc24-4ea8-b8d6-5090c762912c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Split API URLs to second project/settings/wsgi ?

Jason-6
What you can do is split the backend into a REST API using http://www.django-rest-framework.org/

Refactor the views to share common logic, and you can have your template renders bound to one view handler and an api call to another.   Configure your urls.py to have a url like /api/{version}/{resource/{id} mapped to an API endpoint.  Since the logic is shared between the different views, you'll get the same results regardless of access method.

The nice part with DRF views is you can customize the permissions and authentications for specific resources.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cabb7821-78ff-4a63-9919-f7e9cfc5f6e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Split API URLs to second project/settings/wsgi ?

guettli-3


Am Dienstag, 2. Januar 2018 13:47:40 UTC+1 schrieb Jason:
What you can do is split the backend into a REST API using <a href="http://www.django-rest-framework.org/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.django-rest-framework.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGjl9dNBVH-EtBzln4iQdn10YtnzQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.django-rest-framework.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGjl9dNBVH-EtBzln4iQdn10YtnzQ&#39;;return true;">http://www.django-rest-framework.org/

Refactor the views to share common logic, and you can have your template renders bound to one view handler and an api call to another.   Configure your urls.py to have a url like /api/{version}/{resource/{id} mapped to an API endpoint.  Since the logic is shared between the different views, you'll get the same results regardless of access method.

The nice part with DRF views is you can customize the permissions and authentications for specific resources.


Yes, this (customize the permissions and authentications for specific resources) sounds very good.

I have other applications where this could be needed. But up to now they don't use DRF.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/18deac16-b856-455d-b3e8-941fffd0dde2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Split API URLs to second project/settings/wsgi ?

Jason-6
Sounds like this is a good use case to integrate DRF to solve multiple problems.



On Wednesday, January 3, 2018 at 7:57:46 AM UTC-5, guettli wrote:


Am Dienstag, 2. Januar 2018 13:47:40 UTC+1 schrieb Jason:
What you can do is split the backend into a REST API using <a href="http://www.django-rest-framework.org/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.django-rest-framework.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGjl9dNBVH-EtBzln4iQdn10YtnzQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.django-rest-framework.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGjl9dNBVH-EtBzln4iQdn10YtnzQ&#39;;return true;">http://www.django-rest-framework.org/

Refactor the views to share common logic, and you can have your template renders bound to one view handler and an api call to another.   Configure your urls.py to have a url like /api/{version}/{resource/{id} mapped to an API endpoint.  Since the logic is shared between the different views, you'll get the same results regardless of access method.

The nice part with DRF views is you can customize the permissions and authentications for specific resources.


Yes, this (customize the permissions and authentications for specific resources) sounds very good.

I have other applications where this could be needed. But up to now they don't use DRF.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d2713d86-ff22-4ebf-82db-5e41d54925dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Split API URLs to second project/settings/wsgi ?

guettli-3


Am Mittwoch, 3. Januar 2018 17:40:51 UTC+1 schrieb Jason:
Sounds like this is a good use case to integrate DRF to solve multiple problems.



I am unsure. I would like to have auth solved by the framework. With framework I mean django.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4d127ad9-3cb3-4fbd-88fd-cbcebcc5ffd6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Split API URLs to second project/settings/wsgi ?

guettli-3
By chance I saw this in the authenticate() docs:

https://docs.djangoproject.com/en/2.0/topics/auth/default/#django.contrib.auth.authenticate

 Changed in Django 1.11: The optional request argument was added.

Maybe this is the reason why DRF did his own auth handling in the past.

Regards,
  Thomas Güttler

Am Donnerstag, 4. Januar 2018 16:54:38 UTC+1 schrieb guettli:


Am Mittwoch, 3. Januar 2018 17:40:51 UTC+1 schrieb Jason:
Sounds like this is a good use case to integrate DRF to solve multiple problems.



I am unsure. I would like to have auth solved by the framework. With framework I mean django.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/39ed54c5-dc32-4d9a-b284-7d0dfb8c183d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.