RabbinatixDocs
Sign inGet started

Example

Check a form before calling an API

Event / UI action logic runs in the website when a person does something. This newsletter form cleans the email, checks it on the page so a typo never costs a network call, and only then calls the API.

You will build

  • The POST /api/v1/newsletter API, connected to the web app
  • The Join newsletter form logic on Web App
  • A quick test of both paths

System map

  • Web AppAuth ServicePOST /api/v1/newsletter

Uses Web App and Auth Service from the Login example. Any website and backend service will do.

Part 1: Declare and connect the API

  1. 1.

    Open Auth Service → APIs → Add an API. Provided, POST, /api/v1/newsletter. Request body email: string. Change 200 to 204 with no body. Click Create endpoint.

  2. 2.

    Open Web App → … → Add a dependency…, provider Auth Service, tick POST /api/v1/newsletter, click Connect 1 API.

Part 2: Build the form logic

  1. 1.

    Open Web App → Logic → + Logic. Choose Event / UI action. Event name and name Join newsletter. Input email (Text). Return values joined (Yes / No) and message (Text). Click Create and open.

  2. 2.

    Add Trim on email, then To Lower Case on its result.

  3. 3.

    Add Validate Email on the lower-case result (Field name email) and a Branch Email looks right? on its valid. Connect the On Event arrow into the Branch.

  4. 4.

    From False: Return with joined = false and message from the validation message.

  5. 5.

    From True: Make Object email: string from the lower-case result, then Call Contract POST /api/v1/newsletter with it as body.

  6. 6.

    From 204: Return with joined = true and message = You’re on the list. From Other: joined = false, message = Something went wrong.

Check: The Problems tab is empty.

Part 3: Test it

  1. 1.

    Click Test with email = Nia@Example.COM . The call goes out with nia@example.com.

  2. 2.

    Run again with email = nia-at-example. The False path lights up and nothing is called.