@hateoas-ts/resource - v1.4.3
    Preparing search index...

    Interface Action<TEntity>

    Represents an executable hypermedia action (form submission).

    Actions are discovered from HAL-Forms templates and enable HATEOAS-driven state transitions. They encapsulate the HTTP method, target URI, content type, and available form fields.

    // Discover and execute an action
    if (state.hasActionFor('create-post')) {
    const action = state.actionFor('create-post');

    // Check available fields
    const titleField = action.field('title');
    console.log(titleField?.required);

    // Submit the action
    const result = await action.submit({
    title: 'Hello World',
    content: 'My first post'
    });
    }
    • State.actionFor for discovering actions
    • Form for the underlying form structure
    interface Action<TEntity extends Entity> {
        contentType: string;
        extensions?: Record<string, unknown>;
        fields: Field[];
        formSchema: ActionFormSchema;
        method: string;
        name: string;
        title?: string;
        uri: string;
        field(name: string): Field | undefined;
        submit(formData: Record<string, SafeAny>): Promise<State<TEntity>>;
    }

    Type Parameters

    • TEntity extends Entity

      The expected entity type of the response

    Hierarchy

    • Form
      • Action
    Index

    Properties

    contentType: string

    Content-Type for the form submission body.

    extensions?: Record<string, unknown>

    Non-standard HAL-FORMS template members preserved from the backend.

    This is where control-plane hints such as x-available, x-blockedBy, x-effects, and x-returns are exposed without changing the HAL-FORMS shape.

    fields: Field[]

    Available form fields.

    formSchema: ActionFormSchema

    Schema generated from form fields.

    Uses the Standard Schema interface so validation engines are pluggable.

    method: string

    HTTP method for submission (e.g., 'POST', 'PUT', 'DELETE').

    name: string

    Form/action name (sometimes called 'rel').

    title?: string

    Human-readable form title.

    uri: string

    Target URI for form submission.

    Methods

    • Retrieves a form field by name.

      Parameters

      • name: string

        The field name

      Returns Field | undefined

      The Field object or undefined if not found