Automatically generate jsonapi endpoints from simple schemas
https://jesseditson.github.io/ember-jsonapi/tutorial-modules.html#jsonapi-express
This module is intended to be called with a schema object, as created by jsonapi-schema:
var JSONAPI = require('jsonapi-express');
var schema = require('jsonapi-schema');
var path = require('path');
var schemas = schema.loadSchemas(path.join(process.cwd(), 'app'));
var operations = {}; // more on operations below
app.use('/api', JSONAPI(operations, schemas, '/api'));
Operations are expected to contain a key per model, with any of the following operations defined:
findAll
: a function for finding recordsfindOne
: a function for finding a single recordcreate
: a function for creating a recordupdate
: a function for creating a recorddelete
: a function for deleting a recordupdateRelationship
: a function for updating the relationship between two records
If not defined, the operation will be automatically skipped and the request will continue back to your application.
This module then adds the following endpoints for each model. Assuming a model called article
, this lib would add the following routes:
GET /api/articles (findAll)
GET /api/articles/:id (findOne)
POST /api/articles (create)
PATCH /api/articles/:id (update)
DELETE /api/articles/:id (delete)
GET /api/articles/:id/comments (findOne or findAll, depending on relationship type)
GET /api/articles/:id/relationships/comments (findAll)
POST /api/articles/:id/relationships/comments (updateRelationship)
PATCH /api/articles/:id/relationships/comments (updateRelationship)
DELETE /api/articles/:id/relationships/comments (updateRelationship)