Native 4D to make REST request to Django application

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Native 4D to make REST request to Django application

4D Tech mailing list
I am looking for assistance with developing a REST interface to a Django application using native 4D v16R6 commands.  Is it possible to do this?  I have been given a username, Password, and Basic Authorization token and  I have tried using the HTTP AUTHENTICATE command to set username and password, and then adding the Authorization to the http header but I am not getting back the expected JSON results using the HTTP Get function.

Any suggestions would be appreciated!

Thank you,
Brad Olson
CommScope, Inc.
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Native 4D to make REST request to Django application

4D Tech mailing list
I'm not familiar with Django, but here are some suggestions after a quick look at their API. They show an examples here with curl.

https://www.django-rest-framework.org/tutorial/quickstart/

https://www.django-rest-framework.org/api-guide/authentication/

If you run these adding the --verbose option you should be able to get an accurate picture of what is sent and received. From there you can probably figure out what is going wrong with your 4D implementation.

John DeSoi, Ph.D.


> On Dec 10, 2018, at 5:52 PM, Olson, Brad via 4D_Tech <[hidden email]> wrote:
>
> I am looking for assistance with developing a REST interface to a Django application using native 4D v16R6 commands.  Is it possible to do this?  I have been given a username, Password, and Basic Authorization token and  I have tried using the HTTP AUTHENTICATE command to set username and password, and then adding the Authorization to the http header but I am not getting back the expected JSON results using the HTTP Get function.

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Native 4D to make REST request to Django application

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Django is a python web framework. Django Rest Framework (DRF) is a plugin that facilitates adding a REST Api. It’s the most popular plugin for this,  but it’s not the only way to do it.

When I did this before there was an explicit call to get the token - the django developer created it. They may have used the default path, I’m not sure (/get-token)  I used the 4D command :
HTTP AUTHENTICATE($user;$password)
for the request to get the token.

Thereafter I used the token in the header and built the headers using arrays with HTTP Request… In my case the format for the header was:

Header Name: Authorization, Header Value : Token <token value>


> On Dec 10, 2018, at 3:52 PM, Olson, Brad via 4D_Tech <[hidden email]> wrote:
>
> I am looking for assistance with developing a REST interface to a Django application using native 4D v16R6 commands.  Is it possible to do this?  I have been given a username, Password, and Basic Authorization token and  I have tried using the HTTP AUTHENTICATE command to set username and password, and then adding the Authorization to the http header but I am not getting back the expected JSON results using the HTTP Get function.
>
> Any suggestions would be appreciated!
>
> Thank you,
> Brad Olson
> CommScope, Inc.
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Native 4D to make REST request to Django application

4D Tech mailing list
HTTP AUTHENTICATE will build these headers for you.


> On Dec 10, 2018, at 9:43 PM, Lee Hinde via 4D_Tech <[hidden email]> wrote:
>
> HTTP AUTHENTICATE($user;$password)
> for the request to get the token.
>
> Thereafter I used the token in the header and built the headers using arrays with HTTP Request… In my case the format for the header was:
>
> Header Name: Authorization, Header Value : Token <token value>

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************