RabbinatixDocs
Sign inGet started

Example

Call the price function from an API

Write a function once, call it everywhere. A quote API on the checkout service takes a subtotal and a discount, calls Price with tax with the shop’s tax rate and answers with the total. A wrong request gets a 400 instead of an error.

You will build

  • The POST /api/v1/quotes API on Checkout Service
  • Endpoint logic that calls Price with tax
  • Where used, linking the function to its callers

System map

  • StorefrontCheckout ServicePOST /api/v1/quotes

Do the Price with tax example first. Checkout Service comes from the Online shop example; any backend service will do.

Part 1: Declare the quote API

  1. 1.

    Open Checkout Service → APIs → Add an API. Provided, POST, /api/v1/quotes, summary Price a cart, lifecycle To do.

  2. 2.

    Request body:

    subtotal: number
    discount?: number
  3. 3.

    200 body total: number. Click +400, body error: string. Click Create endpoint.

Part 2: Build the endpoint logic

  1. 1.

    On the POST /api/v1/quotes row, click + Logic.

  2. 2.

    Add Break Object fed from On Request body:

    subtotal: number
    discount?: number
  3. 3.

    Add Default Value: value from discount, fallback = 0. A missing discount counts as none.

  4. 4.

    Add Validate Range on subtotal with Field name subtotal, Min 0, and clear Max. Then a Branch Subtotal valid?.

  5. 5.

    From False: Return Response 400, body Make Object error: string from the validation message.

  6. 6.

    From True: add Call Function. In Details, pick Price with tax. Its connection points are the function’s inputs and outputs. Connect subtotal, taxRate = 0.12, and discount from the Default Value result.

  7. 7.

    Then Return Response 200, body Make Object total: number from the call’s total.

Check: The Problems tab is empty.

Part 3: Test it and find the callers

  1. 1.

    Click Test. Body { "subtotal": 100 } answers 200 with total 112. Body { "subtotal": -5 } answers 400.

  2. 2.

    Open Price with tax and its Where used tab: the quote logic is listed under Called by. Change the function, and every caller gets the change.