GET/use-cases200 OK
What you can build with RequestScript
Let clients compose API calls, ship business rules as versioned contracts, and integrate with other systems on your terms. Here are some of the ways it fits.
Composable APIs
Let clients describe exactly what they need in one round trip. A script calls the resources your server exposes, combines the results and returns only the shape the client wants, without adding a new endpoint for every screen.
Learn morerequest Dashboard {
const weather: com.example.Weather
const inventory: shop.Inventory
const oslo = weather.temperature(city: "Oslo")
const mugs = inventory.stock(sku: "RS-MUG")
return {
temperature: oslo.value,
mugsInStock: mugs.value,
}
}Pricing and business rules
Exact decimal arithmetic and bounded decimal(p, s) types make RequestScript a natural fit for prices, taxes, discounts and fees. Rules live in contracts that product teams can read, not in deploys.
Learn morecontract billing.Discount(total: decimal(8, 2), loyaltyYears: int32) {
var rate: decimal = 0
if (loyaltyYears >= 5) {
rate = 0.15
} else if (loyaltyYears >= 2) {
rate = 0.05
}
return total - total * rate
}Versioned workflows
Contracts are immutable and keyed by path, name and version. Publish @2 alongside @1, move clients over when they are ready, and always know exactly which logic produced a result.
Learn morecontract onboarding.Welcome@2(name: string, plan: string) {
if (plan == "team") {
return "Welcome aboard, ${name}! Invite your team to get started."
}
return "Welcome aboard, ${name}!"
}Safe, controlled integrations
Scripts can only reach the outside world through resources the host chooses to expose, and there are no loops to run away with. Resource failures come back as values the script can handle, so partial outages degrade gracefully.
Learn morerequest OrderStatus {
const inventory: shop.Inventory
const stock = inventory.stock(sku: "RS-SHIRT")
if (stock.error != null) {
return { available: false, reason: stock.error.message }
}
return { available: stock.value > 0 }
}An embedded rules engine
The interpreter is a dependency-free TypeScript library. Store scripts alongside your data and evaluate them in your own Node service, edge function or browser app, with your own resources and your own invoker.
Learn morecontract alerts.ShouldNotify(reading: object, threshold: decimal) {
if (reading.value == null) {
return false
}
return reading.value > threshold && reading.muted != true
}…and much more
Start with the Quickstart to run your first request and save your first contract, or try the playground right in your browser.