Answer the question
In order to leave comments, you need to log in
How to implement imitation of getting data via API?
Good afternoon,
How to simulate receiving data via API, if only a json file is given in the test task. I don't quite understand what they want from me.
Answer the question
In order to leave comments, you need to log in
simulate get request to json
export default class GetService{
_apiBase = 'http://localhost:3000';
async getResource(url) {
const res = await fetch(`${this._apiBase}${url}`);
if (!res.ok) {
throw new Error(`Could not fetch ${url}` +
`, received ${res.status}`);
}
return await res.json();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question