import requests



class RestClient:

    def __init__(self, baseurl: str, token: str | None = None):
        self.baseurl = baseurl
        self.token = token

    def _headers(self) -> dict:
        if self.token:
            return {"Authorization": f"Token {self.token}"}
        return {}

    def get(self, endpoint: str):
        url = f"{self.baseurl}/{endpoint}"
        response = requests.get(url, headers=self._headers())
        return response.json()

    def put(self, endpoint: str, payload: dict):
        url = f"{self.baseurl}/{endpoint}"
        response = requests.put(url, json=payload, headers=self._headers())
        response.raise_for_status()
        return response.json()