diff --git a/src/api/StorageServiceAPI.js b/src/api/StorageServiceAPI.js index 0a3934b..bac842d 100644 --- a/src/api/StorageServiceAPI.js +++ b/src/api/StorageServiceAPI.js @@ -1,6 +1,6 @@ import axios from 'axios'; -import {API_URL, ENDPOINT} from './consts'; +import {API_URL, ENDPOINT, TESTING_HEADERS} from './consts'; /** * @interface Store @@ -19,12 +19,21 @@ import {API_URL, ENDPOINT} from './consts'; class StorageServiceApi { URL = `${API_URL}${ENDPOINT}`; + get defaultConfig () { + if (location.hostname.includes('localhost')) { + return { + headers: TESTING_HEADERS, + }; + } + return {}; + } + /** * Запрос полного списка всех api * @returns {Promise} - Возвращает список всех api */ request = async () => { - const {data} = await axios.get(this.URL); + const {data} = await axios.get(this.URL, this.defaultConfig); return data; } @@ -34,7 +43,7 @@ class StorageServiceApi { * @returns {Promise} - Возвращает api по указанному ключу */ find = async (key) => { - const {data} = await axios.get(`${this.URL}/${key}`); + const {data} = await axios.get(`${this.URL}/${key}`, this.defaultConfig); return data; } @@ -44,7 +53,7 @@ class StorageServiceApi { * @returns {Promise} - Возвращает вновь созданный элемент */ create = async (createData) => { - const {data} = await axios.post(this.URL, createData); + const {data} = await axios.post(this.URL, createData, this.defaultConfig); return data; } @@ -54,7 +63,7 @@ class StorageServiceApi { * @returns {Promise} - Возвращает обновленный элемент */ update = async (updateData) => { - const {data} = await axios.put(this.URL, updateData); + const {data} = await axios.put(this.URL, updateData, this.defaultConfig); return data; } @@ -64,7 +73,7 @@ class StorageServiceApi { * @returns {Promise} - Возвращает удаленный элемент */ remove = async (key) => { - const {data} = await axios.delete(`${this.URL}/${key}`); + const {data} = await axios.delete(`${this.URL}/${key}`, this.defaultConfig); return data; } } diff --git a/src/api/consts.js b/src/api/consts.js index 02cea95..9a32147 100644 --- a/src/api/consts.js +++ b/src/api/consts.js @@ -3,5 +3,6 @@ export const API_URL = 'http://api.storage.vigdorov.ru'; export const ENDPOINT = '/store'; -export const API_KEYS = { +export const TESTING_HEADERS = { + 'Api-Name': 'store-service-test', }; diff --git a/store.http b/store.http index 360cf3f..cf04675 100644 --- a/store.http +++ b/store.http @@ -1,14 +1,17 @@ // Запрос всех пар ключей апи GET http://vigdorov.ru:4001/store HTTP/1.1 +Api-Name: store-service-test ### // Запрос апи по ключу GET http://vigdorov.ru:4001/store/testApi HTTP/1.1 +Api-Name: store-service-test ### // Создание нового апи POST http://vigdorov.ru:4001/store HTTP/1.1 content-type: application/json +Api-Name: store-service-test { "key": "testApi", @@ -25,6 +28,7 @@ content-type: application/json // Обновление существующего апи PUT http://vigdorov.ru:4001/store HTTP/1.1 content-type: application/json +Api-Name: store-service-test { "key": "testApi", @@ -39,4 +43,5 @@ content-type: application/json ### // Удаление апи -DELETE http://vigdorov.ru:4001/store/testApi HTTP/1.1 \ No newline at end of file +DELETE http://vigdorov.ru:4001/store/testApi HTTP/1.1 +Api-Name: store-service-test