import axios from 'axios'; export default class ApiService { private readonly baseUrl: string = 'http://core.sandd'; private readonly apiRoutes = { file: '/api/file', searchAndDisplace: '/search-and-displace' }; constructor() {} /** * Upload a file to the server and return its response. * Throws an error if the response wasn't successful * * @param file * @returns */ public async uploadFile(file: File) { let formData = new FormData(); formData.append('file', file); try { let response = await axios.post( this.baseUrl + this.apiRoutes.file, formData, { headers: { 'Content-Type': 'multipart/form-data' } } ) return response.data; } catch (err) { throw err; } } /** * Get data for a file from the server. * Throws an error if the response wasn't successful * * @param fileId * @returns */ public async getFileData(fileId: string) { try { let response = await axios.get(this.baseUrl + this.apiRoutes.searchAndDisplace + `/${fileId}`); return response.data; } catch (err) { throw err; } } }