waterline-jsonapi

Create JSONAPI compliant payloads from Waterline blueprints.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

4

Maintenance

Last Commit

5yrs ago

Contributors

3

Package

Dependencies

6

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

waterline-jsonapi

Build Status Coverage Status Code Climate Known Vulnerabilities

Create JSON API compliant payloads from Waterline blueprints and query results and get a promise in return.

npm i waterline-jsonapi --save

Usage

You need only your query results and your collection to get started. Assuming the example user and pet collections.

const Waterline_JSONAPI = require("waterline-jsonapi")

// The query
User
  .find()
  .populate("pets")

  // Create a JSON API payload from the results.
  .then(user_and_pets => {
    const jsonapi = new Waterline_JSONAPI(user_and_pets, User).generate()
    reply(jsonapi)
  })

// Or with a Promise

User
  .find()
  .populate("pets")

  // Create a JSON API payload from the results.
  .then(user_and_pets => {
    new Waterline_JSONAPI(user_and_pets, User).generate(true) // Note: the true here.

      // Reply with your data.
      .then(payload => reply(payload))

      // If there was an unlikely error, you can catch here.
      .catch(error => reply(error))
  })

The above will reply with a valid JSONAPI payload, the same works by passing in an Error or an object with is_error: true.

Links are retrieved from your collections if they have any of the following functions.

All links functions are passed a single resource object and a meta object passed into the constructor.

get_self_link(resource, meta)
get_next_link(resource, meta)
get_last_link(resource, meta)
get_related_link(resource, meta)

Inside of the meta object is a context variable passed in by this library, it is a string and one of these values:

"related"
"single"
"list"

For you to return the appropriate link.

Meta

You can define metadata on your collection in the get_meta function. This function takes no arguments and should return an object.

API

This version is a 100% rebuild from the ground up and all previous API methods have been deprecated and removed as they were invalid.

MIT License © New World Code

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial