sercrod

*post

Summary

*post sends the current Sercrod host data as JSON via HTTP POST to a given URL and writes the JSON response back into host data. It is typically attached to a button or similar control inside a Sercrod host. *post and n-post are aliases.

Key points:

Basic example

A minimal contact form that posts all data and stores the response in result:

<serc-rod id="contact" data='{
  "form": { "name": "", "message": "" },
  "result": null
}'>
  <form>
    <label>
      Name:
      <input type="text" *input="form.name">
    </label>

    <label>
      Message:
      <textarea *input="form.message"></textarea>
    </label>

    <button type="button" *post="/api/contact.php:result">
      Send
    </button>
  </form>

  <p *if="result">
    <strong>Server response:</strong>
    <span *print="result.status"></span>
  </p>
</serc-rod>

Behavior in this example:

Behavior

Attachment and rendering:

Important consequence:

Trigger timing:

Request specification

The attribute value for *post uses a compact URL[:prop] format:

Format:

Processing rules:

Restrictions and details:

Data source and JSON encoding

Source of data:

Encoding:

The exact JSON string that will be sent is also exposed to the lifecycle events for debugging and logging.

Response handling and writeback

Once the POST request completes, the response is handled in two stages:

  1. Derive a value and text from the HTTP response.
  2. Write value back into host data according to prop.

Content negotiation:

Data writeback:

Tracking:

State flags and error reporting

*post shares the same state slots as *api and *fetch:

Request lifecycle:

Log output:

Ephemeral nature of $upload and $download:

Events

*post emits three dedicated events during its lifecycle:

All three events bubble and are composed, so you can listen for them at the host level or higher in the DOM tree.

Integration with staged data (*stage, *apply, *restore)

*post is designed to cooperate with Sercrod's staging directives:

Implications:

Relation to *fetch and *api

*post shares several concepts with *fetch and *api, but with distinct responsibilities:

When to use which:

Because *post, *fetch, and *api all treat HTTP communication as “JSON in, JSON out” and share the same state flags, it is natural to standardize server-side handlers around this contract.

Recommended approach on the server:

Benefits for server-side code:

Position in Sercrod’s design:

Best practices

Notes