Giter VIP home page Giter VIP logo

bookshelf-jsonapi's Introduction

Build Status

bookshelf-jsonapi

Simple library that uses Bookshelf models and relationships to create a RESTful api based on jsonapi.org spec using an express 4 compatible middleware.

Usage

Define your Bookshelf models and their relationships. Pass an object to the jsonapi middleware that contains 'resourceName' => 'modelReference'. This should allow your application to serve jsonapi compatible rest services with very little setup.

var jsonapi = require('jsonapi-bookshelf');
var models = require('./models'); // key model name, value model object

app.use('/api', jsonapi(models));

Please refer to the tests to see detailed examples of how the middlware works

bookshelf-jsonapi's People

Contributors

jthoms1 avatar spbrien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bbb jpchip

bookshelf-jsonapi's Issues

Attributes property

Hey, just reading through your tests and notice that properties are not placed under an "attributes" key. Is this due to jsonapi being at an older version at the time of writing?

Examples for Interface

README.md should include better examples for how to use the interface of the middleware.

Updating 'to-many' relationships through PUT

If a to-many relationship is included in the links section of a resource object, it MUST be an object containing:

  • type and ids members for homogeneous to-many relationships; to clear the relationship, set the ids member to []
  • a data member whose value is an array of objects each containing type and id members for heterogeneous to-many relationships; to clear the relationship, set the data member to []

http://jsonapi.org/format/#crud-updating-resource-to-many-relationships

Implement pagination

Implement pagination of collections.

Pagination links MUST appear in the link object that corresponds to a collection. To paginate the primary data, include pagination links in the top-level links object. To paginate a linked collection returned in a compound document, include pagination links in the corresponding link object.

http://jsonapi.org/format/#fetching-pagination

Remove relationships with DELETE method

If the client makes a DELETE request to a relationship URL, the server MUST delete the specified members from the relationship or return a 403 Forbidden response. If all of the specified resources are able to be removed from, or are already missing from, the relationship then the server MUST return a successful 204 No Content response.

  • Note: As described above for POST requests, this approach helps avoid pointless race conditions between multiple clients making the same changes.

http://jsonapi.org/format/#crud-updating-to-many-relationships

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.