@flethy/flow
TypeScript icon, indicating that this package has built-in type declarations

0.0.350 • Public • Published

flethy connectors

What and Why?

flethy connectors is a zero-dependency library that provides http configs for a number of web3 (and web2) APIs in a simple way. The whole library is fully typed and gives easy access to the included APIs.

Motivated to implement for a simple reason: less dependencies in your own projects. What I have done so far:

  1. I want to use a service.
  2. I'm looking for a corresponding SDK or a suitable package that simplifies the integration with.
  3. Profit

What I haven't done: examine each package for their deployed dependencies. The effect is that my own application gets unnecessarily many dependencies, and strictly speaking I can't be completely sure what happens inside the library. Of course, this also opens up some attack vectors.

With flethy you don't get any additional dependency. It just contains an easy to use and typed API to use services. It is ultimately up to the user which http client to use (got, axios, fetch, ...). The config is mapped to the config of the http client and done.

A significant advantage in my opinion are the provided interfaces. If I connect a new API, or connect an API that I already know but haven't used for a while, I always have to invest time to find out how to use the API: Authorization, headers, payload, paths, ... The types in flethy make the integration much more effective and efficient, because less mistakes happen and you get the expected result faster.

flethy in action

Installation

npm i @flethy/connectors
# or
yarn add @flethy/connectors

Usage

The package consists of one function, and various namespaces that abstract the service APIs. Below is an example of uploading a JSON file to Web3Storage:

import { nao, Web3Storage } from '@flethy/connectors'

const requestConfig = nao<Web3Storage.UploadContent>({
  kind: 'web3storage.upload.content',
  'auth:Authorization': process.env.WEB3_STORAGE_API_TOKEN,
  'body:content': {
    testString: 'testString',
    testNumber: 1,
    testBoolean: true,
  },
})

The following JSON represents the content of requestConfig:

{
  "method": "POST",
  "url": "https://api.web3.storage/upload",
  "headers": {
    "Authorization": "Bearer WEB3_STORAGE_TOKEN"
  },
  "body": {
    "content": {
      "testString": "testString",
      "testNumber": 1,
      "testBoolean": true
    }
  }
}

Find all available service API configurations here.

Integrate with http client (axios)

With the above example it's just the following code to execute the http request by using axios:

Install axios:

npm i axios
# or
yarn add axios

Use it the following way:

import axios from 'axios'
import { nao, Web3Storage } from '@flethy/connectors'

// create your request config

const requestConfig = nao<...>({...})

// execute http request

async function main() {
  const response = await axios({
    method: requestConfig.method,
    url: requestConfig.url,
    headers: requestConfig.headers,
    data: requestConfig.body,
  })
  return response
}

main()

Supported Endpoints

Find a list of all supported endpoints here.

Contribution

The number of integrated APIs is severely limited so far. Services that I need on a regular basis are integrated. More integrations happen on feedback basis, because I personally need another integration, or because someone implements an API configuration.

I'm very happy if you add more APIs and so more services can be easily connected via flethy. Just create a branch, and as soon as a configuration is ready create a new PR for it.

Remark

I am of course aware that the approach I am taking with flethy is not complete or limited. It will be difficult with pure on-board tools to cover all conceivable scenarios. Take for example APIs that expect multiform data, or files to be transferred. Or header information for interaction with AWS services, where certain crypto signatures have to be used. In these cases, it must ultimately be decided what is more important: a simple API or no dependencies. But this question can be answered when the time comes ;)

To make the use of flethy as comfortable as possible, a lot of information is included in the API config. This includes for example the URL of the API. Of course you have to trust that this information is correct. In the first step, I will always manually check that a PR is not redirecting API endpoints to possibly malicious endpoints. In the future, I will think of an automated mechanism to validate this.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.3501latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.3501
0.0.3490
0.0.3480
0.0.3470
0.0.3460
0.0.3450
0.0.3440
0.0.3430
0.0.3420
0.0.3410
0.0.3400
0.0.3390
0.0.3380
0.0.3370
0.0.3360
0.0.3351
0.0.3340
0.0.3330
0.0.3320
0.0.3310
0.0.3300
0.0.3290
0.0.3280
0.0.3271
0.0.3260
0.0.3250
0.0.3240
0.0.3230
0.0.3220
0.0.3210
0.0.3200
0.0.3190
0.0.3180
0.0.3170
0.0.3160
0.0.3150
0.0.3140
0.0.3130
0.0.3120
0.0.3110
0.0.3100
0.0.3090
0.0.3080
0.0.3070
0.0.3060
0.0.3040
0.0.3030
0.0.3020
0.0.3010
0.0.3000
0.0.2990
0.0.2981
0.0.2971
0.0.2960
0.0.2950
0.0.2940
0.0.2930
0.0.2920
0.0.2910
0.0.2900
0.0.2890
0.0.2880
0.0.2870
0.0.2860
0.0.2850
0.0.2840
0.0.2830
0.0.2820
0.0.2811
0.0.2800
0.0.2790
0.0.2780
0.0.2770
0.0.2760
0.0.2750
0.0.2740
0.0.2730
0.0.2720
0.0.2711
0.0.2700
0.0.2690
0.0.2680
0.0.2670
0.0.2660
0.0.2651
0.0.2640
0.0.2630
0.0.2620
0.0.2611
0.0.2601
0.0.2590
0.0.2580
0.0.2570
0.0.2560
0.0.2550
0.0.2540
0.0.2530
0.0.2521
0.0.2510
0.0.2500
0.0.2490
0.0.2480
0.0.2471
0.0.2460
0.0.2450
0.0.2440
0.0.2430
0.0.2420
0.0.2410
0.0.2400
0.0.2390
0.0.2380
0.0.2370
0.0.2360
0.0.2350
0.0.2340
0.0.2330
0.0.2320
0.0.2311
0.0.2300
0.0.2290
0.0.2281
0.0.2270
0.0.2260
0.0.2250
0.0.2240
0.0.2230
0.0.2220
0.0.2211
0.0.2200
0.0.2191
0.0.2180
0.0.2170
0.0.2161
0.0.2151
0.0.2140
0.0.2131
0.0.2120
0.0.2110
0.0.2101
0.0.2091
0.0.2080
0.0.2070
0.0.2060
0.0.2050
0.0.2041
0.0.2031
0.0.2020
0.0.2010
0.0.2000
0.0.1990
0.0.1980
0.0.1970
0.0.1960
0.0.1950
0.0.1940
0.0.1931
0.0.1920
0.0.1910
0.0.1900
0.0.1890
0.0.1880
0.0.1870
0.0.1861
0.0.1851
0.0.1841
0.0.1831
0.0.1821
0.0.1810
0.0.1800
0.0.1790
0.0.1780
0.0.1770
0.0.1760
0.0.1750
0.0.1740
0.0.1730
0.0.1720
0.0.1710
0.0.1700
0.0.1690
0.0.1680
0.0.1670
0.0.1660
0.0.1650
0.0.1640
0.0.1630
0.0.1620
0.0.1610
0.0.1600
0.0.1590
0.0.1580
0.0.1570
0.0.1560
0.0.1550
0.0.1540
0.0.1530
0.0.1520
0.0.1510
0.0.1500
0.0.1490
0.0.1480
0.0.1470
0.0.1460
0.0.1450
0.0.1440
0.0.1430
0.0.1420

Package Sidebar

Install

npm i @flethy/flow

Weekly Downloads

29

Version

0.0.350

License

MIT

Unpacked Size

56.9 kB

Total Files

35

Last publish

Collaborators

  • urbanisierung