from typing import Any, Optional
from httpx import Client


class RequestService:
  def __init__(
    self,
    client: Client,
  ) -> None:
    self.client = client

  def get(self, url: str, **config: Any):
    response = self.client.get(url, **config)
    response.raise_for_status()
    return response.json()

  def post(self, url: str, data: Optional[Any], **config: Any):
    response = self.client.post(url, json=data, **config)
    response.raise_for_status()
    return response.json()

  def delete(self, url: str, **config: Any):
    response = self.client.delete(url, **config)
    response.raise_for_status()
    return response.json()

  def put(self, url: str, data: Optional[Any], **config: Any):
    response = self.client.put(url, json=data, **config)
    response.raise_for_status()
    return response.json()

  def patch(self, url: str, data: Any, **config: Any):
    response = self.client.patch(url, json=data, **config)
    response.raise_for_status()
    return response.json()
