class NewAPI {
request(url) {
return fetch(url);
}
}
class OldAPI {
sendRequest(url, callback) {
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function() {
callback(xhr.responseText);
};
xhr.send();
}
}
class APIAdapter {
constructor(oldAPI) {
this.oldAPI = oldAPI;
}
request(url) {
return new Promise((resolve, reject) => {
this.oldAPI.sendRequest(url, (response) => {
resolve(response);
});
});
}
}
// Usage:
const newAPI = new NewAPI();
const oldAPI = new OldAPI();
const adapter = new APIAdapter(oldAPI);
adapter.request('<https://example.com>')
.then(response => console.log(response));