Url Function
Overview
The url function provides a way to securely access external web resources (data and services)
in a way that can be easily shared.
Importing
The following script demonstrates importing the url function and retrieving data from
a given URL. The following shows importing the funciton in python.
from davinci.python import url
data = url('https://server.com/data.json')
The corresponding code for importing the url function in Javascript is given.
const { url } = require('./davinci/javascript.js');
Authentication Mechanism
The url function will send authentication information to any server that it contacts, if that information has
been configured for the desired server.
- .env file
- authenticaion tokens can be set up in the standard .env envirnoment variable file
- davinci platform tokens
- for users with an account on the davinci platform, any tokens that are configure on the platform
will be included in requests made with the url function, if the user has logged into the platform prior
to running their code.
Security
Security on davinci is managed through the use of tokens, each of which consists of the following
three pieces of information.
- url
- the url is the URL of the resource being protected. It is either the full URL of it can be the first part of the
URL. That is, whenever you access a URL for which consists of the specified URL plus and additional path, the token is active.
- key
- value
- a value associated with the specified key.
Tokens used by your web desktop is managed using the
profile app.
When using the davinci framework in Visual Studio, you have two options for managing your tokens.
If you have defined tokens using the profile app on the davinci server, when you
log into
the davinci servers, your tokens will be imported into your environment and used by the
url
function when retrieving resources.
Cache
The url function above always connects to the inputted URL and retrieves the result.
Sometimes, you may want to save the results to your local hard drive so that the next time
you try to retrieve the data, it just returns the data saved on your hard drive.
This can be accomplished by setting the cache argument to True. Then, the url function first checks
whether the data currently exists in the cache folder in your workspace. If it is there, it returns that
data, otherwise it connects to the specified URL.
from davinci.python import url
data = url(url='https://server.com/data.json', cache=True)
For more information, please see
cache