Skip to content

relztic/restql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

122 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

RestQL.js

RESTful API Resolver for Nested-Linked Resources | ๐Ÿ•ธ ๐Ÿ•ท


npm JavaScript 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

npm install restql

CDN

<script src="https://unpkg.com/restql/dist/umd/index.min.js"></script>

Usage

restql(resource, resolver[, options])

Parameters

  • resource (string): The resource to fetch.
    • Self-explanatory.
Example
'https://pokeapi.co/api/v2/pokemon/1/'
  • resolver (Object): The resolver to apply.
    • At every 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.
Example
{
  '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,
}
Example
{ ... }

Returns

(Promise<Object>): A promise which resolves into an object.

Try It

npm run playground

See Playground

Roadmap

  • Support for authentication
  • Support for optional resolvers
  • Improve package bundler
  • Ability to cache responses
  • Support for recursive resolvers

Take ๐ŸŽ‚, Folks! ๐ŸŒฎ ๐Ÿด ๐Ÿ’จ

About

RESTful API Resolver for Nested-Linked Resources | ๐Ÿ•ธ ๐Ÿ•ท

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors