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
Part 1: Declare and connect the API
- 1.
Open Auth Service → APIs → Add an API. Provided, POST,/api/v1/newsletter. Request bodyemail: string. Change 200 to204with no body. Click Create endpoint. - 2.
Open Web App → … → Add a dependency…, provider Auth Service, tickPOST /api/v1/newsletter, click Connect 1 API.
Part 2: Build the form logic
- 1.
Open Web App → Logic → + Logic. Choose Event / UI action. Event name and name Join newsletter. Inputemail(Text). Return valuesjoined(Yes / No) andmessage(Text). Click Create and open. - 2.
Add Trim on email, then To Lower Case on itsresult. - 3.
Add Validate Email on the lower-case result(Field nameemail) and a BranchEmail looks right?on itsvalid. Connect the On Event arrow into the Branch. - 4.
From False: Return with joined= false andmessagefrom the validationmessage. - 5.
From True: Make Object email: stringfrom the lower-caseresult, then Call ContractPOST /api/v1/newsletterwith it asbody. - 6.
From 204: Return with joined= true andmessage=You’re on the list. From Other:joined= false,message=Something went wrong.
Check:
Part 3: Test it
- 1.
Click Test with email=Nia@Example.COM. The call goes out withnia@example.com. - 2.
Run again with email=nia-at-example. The False path lights up and nothing is called.
