https://github.com/relztic/restql
RESTful API Resolver for Nested-Linked Resources | 🕸 🕷
https://github.com/relztic/restql
api javascript library node npm resolver rest yarn
Last synced: 17 days ago
JSON representation
RESTful API Resolver for Nested-Linked Resources | 🕸 🕷
- Host: GitHub
- URL: https://github.com/relztic/restql
- Owner: relztic
- License: mit
- Created: 2017-10-15T01:00:53.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T09:17:16.000Z (over 2 years ago)
- Last Synced: 2025-06-19T12:47:17.956Z (27 days ago)
- Topics: api, javascript, library, node, npm, resolver, rest, yarn
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/restql/
- Size: 769 KB
- Stars: 17
- Watchers: 0
- Forks: 3
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RestQL.js
RESTful API Resolver for Nested-Linked Resources | 🕸 🕷
---
[](https://www.npmjs.com/package/restql/)
[](https://travis-ci.org/relztic/restql/)
[](https://codeclimate.com/github/relztic/restql/maintainability/)
[](https://codeclimate.com/github/relztic/restql/test_coverage/)
[](https://github.com/prettier/prettier/)RestQL allows you to dynamically resolve the nested-linked resources of a RESTful API.
By specifying a set of properties to describe the paths.
## Installation
### npm
```sh
npm install restql --save
```### Yarn
```sh
yarn add restql
```### CDN
```html
```
## Parameters
### `resource`
`{string} The resource to fetch.`
**Description**
Self-explanatory.
**e.g.:**
```js
'https://pokeapi.co/api/v2/pokemon/1/'
```### `resolver`
`{Object} The resolver to apply.`
**Description**
At each level, each property describes a path to the nested resources within the current one.
RestQL resolves the sames and call the subsequent resolver against them...
Until the base case (`null`) is reached; from which it returns back the merged responses.
**Quantifiers**
Following is a table of the quantifiers you can use:
| Quantifier | Description |
| --- | --- |
| `[]` | Collection of properties. |
| `?` | Optional property. |**e.g.:**
```js
{
'abilities[]?.ability.url': {
'generation.url': {
'main_region.url': null,
},
},
'stats[].stat.url?': {
'affecting_natures.increase[].url': null,
'affecting_natures.decrease[].url': null,
},
'moves[].move?.url': null,
}
```### `[options]`
`{Object} The options to bypass.`
**Description**
[`Request Config`](https://github.com/axios/axios/#request-config)
**e.g.:**
```js
{
// ...
}
```## Usage
```js
// External Packages
import restql from 'restql'/**
* @constant {string} resource The resource to fetch.
*/
const resource = 'https://pokeapi.co/api/v2/pokemon/1/'/**
* @constant {Object} resolver The resolver to apply.
*/
const resolver = {
'abilities[]?.ability.url': {
'generation.url': {
'main_region.url': null,
},
},
'stats[].stat.url?': {
'affecting_natures.increase[].url': null,
'affecting_natures.decrease[].url': null,
},
'moves[].move?.url': null,
}/**
* @constant {Object} options The options to bypass.
*/
const options = {
// ...
};(async () => {
try {
const data = await restql(resource, resolver, options)console.log(data)
} catch (error) {
console.error(error.message)
}
})()
```[Test RestQL in your browser.](https://npm.runkit.com/restql/)
## Roadmap
- ~~Support for authentication~~
- ~~Support for optional resolvers~~
- ~~Improve package bundler~~
- ~~Ability to cache responses~~
- Support for recursive resolversTake 🍰, Folks! 🌮 🐴 💨