Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/osskit/dafka-producer-fetch-client
Typescript-fetch client for dafka-producer
https://github.com/osskit/dafka-producer-fetch-client
dafka fetch kafka producer
Last synced: 9 days ago
JSON representation
Typescript-fetch client for dafka-producer
- Host: GitHub
- URL: https://github.com/osskit/dafka-producer-fetch-client
- Owner: osskit
- License: mit
- Created: 2022-10-16T07:48:33.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T05:18:31.000Z (about 1 year ago)
- Last Synced: 2024-03-15T09:08:01.964Z (9 months ago)
- Topics: dafka, fetch, kafka, producer
- Language: TypeScript
- Homepage:
- Size: 116 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/osskit/dafka-producer-fetch-client/publish.yml) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/osskit/dafka-producer-fetch-client/blob/master/LICENSE.md) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)typescript-fetch client wrapper for `dafka-producer`
## Install
```sh
yarn add @osskit/dafka-producer-fetch-client
```
## Usage
```ts
import { createProducer } from '@osskit/dafka-producer-fetch-client';export const produce = createProducer({
url: 'http://dafka-producer',
topic: 'my-topic',
keyExtractor: (record) => record.id,
fetch: global.fetch,
});await produce(records);
```
### Extra headers
It is possible to add extra headers to the request
```ts
await produce(records, {
'x-extra-header': 'value',
});
```## API
### createProducer({ url, topic, keyExtractor, fetch })
#### url
Type: `string`The URL of `dafka-producer`
#### topic
Type: `string`The Kafka Topic name
#### keyExtractor
Type: `(record: Record) => string`A function to extract the key from a record, defaults to a random `UUID`
#### fetch
Type: `typeof global.fetch`The fetch function to use
#### returns
An instance of a function that receives `(records: Record[], extraHeaders?: object)` and returns `Promise`## License
[MIT License](LICENSE)