PingPong.Service.HTTP (PingPong v0.1.0)

Copy Markdown View Source

Shared HTTP helper used by network-backed services.

The helper JSON-encodes request bodies, sends them with Req, and normalizes HTTP and transport failures into PingPong result tuples. It is intentionally small and service-agnostic so service modules can focus on mapping their own payloads and options.

Summary

Functions

post(url, body, success_status \\ 200)

@spec post(binary(), map(), integer()) :: PingPong.result()

Sends a JSON POST request.

success_status defaults to 200. Services such as Discord can pass a different status, for example 204.

Return values

  • {:ok, response} for the expected HTTP status
  • {:error, {:error_response, response}} for other HTTP responses
  • {:error, {:error, reason}} for transport errors
  • {:error, {:unknown_response, response}} for unexpected Req results