PhoenixGenApi.Structs.Response (PhoenixGenApi v2.15.0)

Copy Markdown View Source

Defines the structure of a response sent back to the client.

This module provides helper functions to create different types of responses, such as synchronous, asynchronous, and error responses.

Summary

Functions

Creates a response for an asynchronous request, indicating that the request has been received and is being processed.

Encodes a Response struct to a map, returning {:ok, map} or {:error, reason}.

Encodes a Response struct to a map using Nestru.

Encodes a Response struct to a map. Opts is not supported yet.

Checks if the response represents an error.

Creates a response for a failed request.

Creates a response to indicate the end of a stream.

Creates a response for a streaming request.

Creates a response for a successful synchronous request.

Types

t()

@type t() :: %PhoenixGenApi.Structs.Response{
  async: boolean(),
  can_retry: boolean(),
  error: String.t() | nil,
  has_more: boolean(),
  request_id: String.t(),
  result: any(),
  success: boolean()
}

Functions

async_response(request_id)

Creates a response for an asynchronous request, indicating that the request has been received and is being processed.

encode(res, opts)

Encodes a Response struct to a map, returning {:ok, map} or {:error, reason}.

encode!(res)

Encodes a Response struct to a map using Nestru.

encode!(res, opts)

Encodes a Response struct to a map. Opts is not supported yet.

error?(response)

Checks if the response represents an error.

error_response(request_id, error, can_retry \\ false)

Creates a response for a failed request.

stream_end_response(request_id)

Creates a response to indicate the end of a stream.

stream_response(request_id, result, has_more \\ true)

Creates a response for a streaming request.

sync_response(request_id, result)

Creates a response for a successful synchronous request.