hyperia.js
v1.0.2
Published
Efficient API bindings for Hyperia
Downloads
1
Readme
Hyperia.JS
Efficient API bindings for Hyperia.
This repository contains official API bindings for Hyperia.
Usage
import hyperia from "hyperia.js"
const h = hyperia("YOUR-API-TOKEN")
await h.checkToken({ doThrow: true }) // will throw an exeception if token is incorrect
const u = await h.users.get("@me")
Intro
This wrapper is being used in production. It has most up-to-date API changes.
Main concept
Hyperia.js's objects are immutable. If you perform any method on an object, it returns a new one. except for Hyperia class.
Hooks
Hyperia.js has a concept of hooks. They are emitted at some point of a request life-cycle.
There are 5 types of hooks - beforeRequest
, request
, requestDone
, requestFailed
, requestSuccessful
.
To add them, you should call function with name of the hook and provide function you want to emit:
hyperia.requester.beforeRequest(req => {
// this code will abort all GET requests
if(req.method == 'GET') {
return false
} else {
return true
}
})
hyperia.requester.onRequest(req => {
// request is gurranteed to be performed
})
hyperia.requester.requestDone(resp => {
// request has been completed without network errors,
// however API errors are still possible
})
hyperia.requester.requestFailed(resp => {
// resp may be undefined. request is failed because of network errors,
// or because of API errors
})
hyperia.requester.requestSuccessful(resp => {
// request was successful
})
Performing request
In case you need to access unimplemented APIs, you can use request
method.
const resp = await hyperia.requester.request<RespData>('/auth/v1/some-secret-method', 'POST', { test: 2 })
Contributing
We'd love to accept your contributions! All we want is following Conventional Commits - that's it.
License
This project is licensed under GNU GPL v3.0.