const API_URL = 'http://localhost:1234'

export async function getJson (url) {
  return (await fetch(url)).json()
}

export function postJson (url, data) {
  return fetch(url, {
    method: 'post',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify(data)
  })
}

export function getContainers () {
  return getJson(`${API_URL}/api/containers`)
}

export function resizeTerminal (containerId, sessionId, cols, rows) {
  return postJson(`${API_URL}/api/containers/${containerId}/sessions/${sessionId}/resize`, {
    cols, rows
  })
}
