export class Request { static async getJSON(url: string): Promise { let result = await fetch( url, { method: 'GET', headers: { 'Accept': 'application/json' } } ); if ( ! result.ok ) { throw new Error( `GET ${url} failed: ${result.status} ${result.statusText}` ); } return result.json() as Promise; } static async postJSON(url: string, input: I): Promise { let result = await fetch( url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: JSON.stringify( input ) }); if ( ! result.ok ) { throw new Error( `POST ${url} failed: ${result.status} ${result.statusText}` ); } return result.json() as Promise; } }