fts-http-client
v1.4.0 typescript serverless lambda function functional faas rpc http client and 5 more...
HTTP Client for Functional TypeScript.
See the main docs for more info on FTS in general.
Note that this client is optional, as FTS HTTP endpoints may be called using any HTTP request library.
The advantage to using this client library is that it performs parameter and return value validation as well as handling JSON encoding / decoding. The custom encoding / decoding is really only used for non-JSON primitive types such as Date
and Buffer
.
Usage
Say we have the following FTS function:
export function example(name: string, date: Date): string {
return `${name}: ${date}`
}
You can invoke this function remotely with the following client code:
import { createHttpClient } from 'fts-http-client'
// previously generated fts definition
const definition = {}
// URL of an fts-http handler endpoint
const url = 'https://example.com/foo'
// create a client that will be used to call the remote FTS function
const client = createHttpClient(definition, url)
// You may either call the remote function with the same signature as the
// original TS function or with an object of named parameters
const result0 = await client('Foo', new Date())
const result1 = await client({ name: 'Foo', date: new Date() })
Alternatives
- Node.js
- Browser
- CLI
License
MIT © Saasify