From 24f9b80ad659f61da89f354b270dd25037080698 Mon Sep 17 00:00:00 2001 From: Nikolay <46225163+vigdorov@users.noreply.github.com> Date: Fri, 17 Jul 2020 22:11:01 +0300 Subject: [PATCH] =?UTF-8?q?HM-49.=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=BE=D0=B5=20=D0=BE=D0=BF=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B0?= =?UTF-8?q?=D0=B7=D1=8B=20=D1=82=D0=B5=D1=81=D1=82=D0=B8=D0=BD=D0=B3=20?= =?UTF-8?q?=D0=B8=D0=BB=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B4=20=D0=B2=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B8=20?= =?UTF-8?q?=D0=BE=D1=82=20url=20=D1=84=D1=80=D0=BE=D0=BD=D1=82=D0=B0=20(#1?= =?UTF-8?q?8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/StorageServiceAPI.js | 21 +++++++++++++++------ src/api/consts.js | 3 ++- store.http | 7 ++++++- 3 files changed, 23 insertions(+), 8 deletions(-) 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