From 6889128571e521acb32558a749b8ae0d9100a631 Mon Sep 17 00:00:00 2001 From: mabashian Date: Tue, 25 Aug 2020 09:08:06 -0400 Subject: [PATCH] Peel axios instantiation out into it's own file so that it can be used in the RelatedAPI model --- awx/ui_next/src/api/AxiosHTTP.js | 13 +++++++++++ awx/ui_next/src/api/Base.js | 14 ++---------- awx/ui_next/src/api/models/Related.js | 31 +++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 awx/ui_next/src/api/AxiosHTTP.js create mode 100644 awx/ui_next/src/api/models/Related.js diff --git a/awx/ui_next/src/api/AxiosHTTP.js b/awx/ui_next/src/api/AxiosHTTP.js new file mode 100644 index 0000000000..f87ee8d78d --- /dev/null +++ b/awx/ui_next/src/api/AxiosHTTP.js @@ -0,0 +1,13 @@ +import axios from 'axios'; + +import { encodeQueryString } from '../util/qs'; + +const AxiosHTTP = axios.create({ + xsrfCookieName: 'csrftoken', + xsrfHeaderName: 'X-CSRFToken', + paramsSerializer(params) { + return encodeQueryString(params); + }, +}); + +export default AxiosHTTP; diff --git a/awx/ui_next/src/api/Base.js b/awx/ui_next/src/api/Base.js index 56492715fb..22b39cc5b2 100644 --- a/awx/ui_next/src/api/Base.js +++ b/awx/ui_next/src/api/Base.js @@ -1,17 +1,7 @@ -import axios from 'axios'; - -import { encodeQueryString } from '../util/qs'; - -const defaultHttp = axios.create({ - xsrfCookieName: 'csrftoken', - xsrfHeaderName: 'X-CSRFToken', - paramsSerializer(params) { - return encodeQueryString(params); - }, -}); +import AxiosHTTP from './AxiosHTTP'; class Base { - constructor(http = defaultHttp, baseURL) { + constructor(http = AxiosHTTP, baseURL) { this.http = http; this.baseUrl = baseURL; } diff --git a/awx/ui_next/src/api/models/Related.js b/awx/ui_next/src/api/models/Related.js new file mode 100644 index 0000000000..8650fa9589 --- /dev/null +++ b/awx/ui_next/src/api/models/Related.js @@ -0,0 +1,31 @@ +import AxiosHTTP from '../AxiosHTTP'; + +class Related { + constructor(http = AxiosHTTP) { + this.http = http; + } + + delete(relatedEndpoint) { + return this.http.delete(relatedEndpoint); + } + + get(relatedEndpoint, params) { + return this.http.get(relatedEndpoint, { + params, + }); + } + + patch(relatedEndpoint, data) { + return this.http.patch(relatedEndpoint, data); + } + + post(relatedEndpoint, data) { + return this.http.post(relatedEndpoint, data); + } + + put(relatedEndpoint, data) { + return this.http.put(relatedEndpoint, data); + } +} + +export default Related;