Skip to content

Function: makeTranslateObjectFormula()

makeTranslateObjectFormula<ParamDefsT, ResultT>(__namedParameters): object & object

Defined in: api.ts:2883

Helper to generate a formula that fetches a list of entities from a given URL and returns them.

One of the simplest but most common use cases for a pack formula is to make a request to an API endpoint that returns a list of objects, and then return those objects either as-is or with slight transformations. The can be accomplished with an execute function that does exactly that, but alternatively you could use makeTranslateObjectFormula and an execute implementation will be generated for you.

Example

`` makeTranslateObjectFormula({ name: "Users", description: "Returns a list of users." // This will generate anexecutefunction that makes a GET request to the given URL. request: { method: 'GET', url: 'https://api.example.com/users', }, response: { // Suppose the response body has the form}, { ...user2 }]. // This "projection" key tells theexecutefunction that the list of results to return // can be found in the object propertyusers`. If omitted, the response body itself // should be the list of results. projectKey: 'users', schema: UserSchema, }, });

Type Parameters

Type Parameter
ParamDefsT extends ParamDefs
ResultT extends Schema

Parameters

Parameter Type
__namedParameters FormulaOptions<ParamDefsT, ObjectArrayFormulaDef<ParamDefsT, ResultT>>

Returns