FunctionScript將 JavaScript 函數(shù)轉(zhuǎn)為類型化的 HTTP API
FunctionScript 是一種將 JavaScript 函數(shù)轉(zhuǎn)為類型化 HTTP API 的語言和規(guī)范。
它允許 JavaScript(Node.js)函數(shù)通過對 HTTP 接口進行定義(包括類型安全機制),從而無縫導(dǎo)出為 HTTP API。
示例代碼
/**
* Select Rows from a Spreadsheet by querying it like a Database
* @param {string} spreadsheetId The id of the Spreadsheet.
* @param {string} range The A1 notation of the values to use as a table.
* @param {enum} bounds Specify the ending bounds of the table.
* ["FIRST_EMPTY_ROW", "FIRST_EMPTY_ROW"]
* ["FULL_RANGE", "FULL_RANGE"]
* @param {object} where A list of column values to filter by.
* @param {object} limit A limit representing the number of results to return
* @ {number} offset The offset of records to begin at
* @ {number} count The number of records to return, 0 will return all
* @returns {object} selectQueryResult
* @ {string} spreadsheetId
* @ {string} range
* @ {array} rows An array of objects corresponding to row values
*/
module.exports = async (
spreadsheetId = null,
range,
bounds = 'FIRST_EMPTY_ROW',
where = {},
limit = {offset: 0, count: 0},
context
) => {
/* implementation-specific JavaScript */
return {/* some data */};
};
上面的代碼將會生成一個 API:
-
spreadsheetIdAstring -
rangeAstring -
boundsAnenum, can be either"FIRST_EMPTY_ROW"or"FULL_RANGE" -
whereAnobject -
limitAnobjectthat must contain:-
limit.offset, anumber -
limit.count, anumber
-
返回一個對象:
selectQueryResult
-
selectQueryResult.spreadsheetIdmust be astring -
selectQueryResult.rangemust be astring -
selectQueryResult.rowsmust be anarray
評論
圖片
表情
