Communicate API
API to communicate frontend with backend. Communicate API
is a wrapper over axios
package with default
request settings for AxiosInstance
out of the box.
Use
The module provides access to the Communicate
class, whose instance contains the session filed. This field
has AxiosInstance
with default or passed request settings. The session
field supports all methods that axios
instance supports.
Example
;const djangoSession = ;djangoSessionsession;
Pass settings
When creating the instance of Communicate
you can redefine or extend default settings via passing custom
settings to Communicate
constructor. Custom settings can contain all the same settings that axios
supports.
Axios request config.
Also the Communicate
has extra settings.
V.1.0.*
Communicate
extra settings
baseUrl
Package determines on what computer the application is running via NODE_ENV
. In case if
NODE_ENV
equal production
the app will use <sheme>://<domaine>
as default baseURL.
Otherwise by default baseURL is http://localhost:8000
. If
you need to define a different baseURL
for developer machine or production you need to add the value to devUrl
key
or prodUrl
key or both in the custom settings object.
Example
const customSettings = devUrl: 'http//127.0.0.1:5000' ...axiosSettings ;const djangoSession = customSettings;
Default axios settings
{
baseURL: (develop) '127.0.0.1:8000' | (production) <scheme>://<domain>
xsrfCookieName: 'csrftoken',
withCredentials: true,
xsrfHeaderName: 'X-CSRFToken',
timeout: 100000,
headers: {
'Content-Type': 'application/json'
}
}