https://github.com/hyper63/connect
@hyper.io/connect is a config module for hyper, making it easy to create hyper urls and tokens with a single connection string
https://github.com/hyper63/connect
Last synced: 9 months ago
JSON representation
@hyper.io/connect is a config module for hyper, making it easy to create hyper urls and tokens with a single connection string
- Host: GitHub
- URL: https://github.com/hyper63/connect
- Owner: hyper63
- Created: 2021-04-23T14:03:25.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-01T11:36:52.000Z (almost 5 years ago)
- Last Synced: 2025-02-14T17:22:06.170Z (about 1 year ago)
- Language: JavaScript
- Size: 18.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
@hyper.io/connect
@hyper.io/connect is a configuration module for hyper clients, this module gives the developer two functions: `url` and `token`, which can take a `hyperio` connection string and create the proper url for a given service and the secure token to access that service.

---
## Table of Contents
- [Getting Started](#getting-started)
- [Installation](#installation)
- [Features](#features)
- [Contributing](#contributing)
- [License](#license)
## Getting Started
Install the `@hyper.io/connect` module
`npm install @hyper.io/connect`
Create an environment variable called `HYPER`
```sh
export HYPER=hyperio://u:p@test.hyper.io/svc
```
Use the `@hyper.io/connect` module in your Data Access Layer (DAL)
```js
import hyper from '@hyper.io/connect'
async function query(selector) {
await fetch(hyper.url('data') + '/_query', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${hyper.token()}`
},
body: JSON.stringify({
selector
})
})
.then(r => r.json())
}
query({ type: 'widget'}).then(console.log.bind(console))
```
## Installation
`npm install @hyper.io/connect`
or
`yarn add @hyper.io/connect`
## Features
* url (service : string, ...paths : string) : string
This method takes a hyper service port as an argument
and optional path argurments and returns a full url
to access the service for an app.
Currently, hyper supports the following service ports:
* data
* cache
* search
* storage
* queue
``` js
import hyper from '@hyper.io/connect'
console.log(hyper.url('search', '_search'))
```
* token ( payload: object ) : string
This method takes no arguments and returns a token based on the
hyper connection string that should give the client secure access
to the hyper service.
## Contributing
All contributions welcome.
## License
Apache 2.0