2020.4.0 • Published 4 years ago
@hp4k1h5/rek v2020.4.0
!! work in progress
rek
mini nodeJs async https wrapper
// `ex.js`
import { Rek } from '@hp4k1h5/rek'
;(async function() {
const rek = new Rek()
await rek.GET('https://api.kanye.rest').then(console.log)
})()
# shell
node ex.js
params:
- options: (Object || string)
- http
options
object- OR
- url string
- http
- autoJSON: (bool)
- returns response as JSON
returns:
- the response byte stream
- OR
- a parsed JSON object
usage
a valid Rek
class instance will accept http or https url addresses or the same options
object as node's http(s?).request
node
install
# shell
yarn add @hp4k1h5/rek
# or
npm i @hp4k1h5/rek
import
import { Rek, rek } from '@hp4k1h5/rek'
;(async function() {
const req = new Rek()
console.log(await req.GET('https://api.kanye.rest'))
// or
rek
.GET({
protocol: 'https:',
host: 'api.kanye.rest',
hostname: 'api.kanye.rest',
pathname: '/',
path: '/',
href: 'https://api.kanye.rest/',
// ...etc
})
.then(console.log)
})()
server
import { rek } from '@hp4k1h5/rek'
;(async function() {
const port = 7357
const endpoints = {
'/': {
GET: (req, res) => {
writeJSON(res, { status: 200, '/': 'ok' })
},
},
}
const server = await rek.listen(port, endpoints)
// listening ...
server.close() // close connection
})()
a rek server will serve endpoints provided as the second parameter. endpoints is a Javascript object of routes and methods.
TODO: implement utility functions are provided by the util
export.
cli
- install rek by running
# shell
yarn add @hp4k1h5/rek # from your `~` root directory
# or
npm i -g @hp4k1h5/rek
- link
rek
by running e.g.yarn link
ornpm link
from the project root, if you download this package
# shell
yarn link # from your `~` directory
# or
npm link # from your `rek` directory
- on the command line, offers cURL like utility
# shell
rek GET https://api.kanye.rest
- or a server
# shell
rek listen 7357 lib/endpoints/endpoints.js
will serve routes exported as default
by ./lib/endpoints/endpoints.js
0.3.8
4 years ago
0.2.7
4 years ago
0.2.6
4 years ago
0.2.5
4 years ago
0.2.4
4 years ago
0.2.3
4 years ago
2020.4.0
4 years ago
0.20200305.2
4 years ago
0.20200305.1
4 years ago
0.20200305.0
4 years ago